Class: RemLint::Runner
- Inherits:
-
Object
- Object
- RemLint::Runner
- Defined in:
- lib/remlint/runner.rb
Overview
Walks paths, extracts Remind out of them, runs the enabled rules, and drops whatever the file itself asked to be quiet about.
Constant Summary collapse
- DISABLE =
# remlint:disable UnbalancedBlocks, TrailingWhitespace, orall. Recognised after either comment character, and mid-line, so it can sit at the end of the line it applies to. /[#;]\s*remlint:disable\s+(?<rules>[\w\s,-]+)/- ALL =
"all"- CANDIDATE =
Extensions worth opening when walking a directory. A file with no extension is opened too, because
examples/astroandexamples/ansitexthave none and are where most of the Remind in that directory lives. /\.(rem|sh|bash)\z|\A[^.]+\z/
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#files(paths) ⇒ Object
The files a set of paths expands to: a named file is taken as given, a named directory is walked.
-
#initialize(config = Config.default) ⇒ Runner
constructor
A new instance of Runner.
- #lint_file(path) ⇒ Object
- #lint_text(path, text) ⇒ Object
-
#run(paths) ⇒ Object
Returns the offences, worst-placed first in reading order.
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
25 26 27 |
# File 'lib/remlint/runner.rb', line 25 def config @config end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
25 26 27 |
# File 'lib/remlint/runner.rb', line 25 def warnings @warnings end |
Instance Method Details
#files(paths) ⇒ Object
The files a set of paths expands to: a named file is taken as given, a named directory is walked.
39 40 41 |
# File 'lib/remlint/runner.rb', line 39 def files(paths) Array(paths).flat_map { |path| (path) }.uniq.reject { |path| config.excluded?(path) } end |
#lint_file(path) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/remlint/runner.rb', line 43 def lint_file(path) text = read(path) if text.nil? [] else lint_text(path, text) end end |
#lint_text(path, text) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/remlint/runner.rb', line 53 def lint_text(path, text) rules = config.rules Extractors.extract(path, text).flat_map do |source| lint_source(Document.new(source), rules) end end |
#run(paths) ⇒ Object
Returns the offences, worst-placed first in reading order.
33 34 35 |
# File 'lib/remlint/runner.rb', line 33 def run(paths) files(paths).flat_map { |path| lint_file(path) }.sort_by(&:sort_key) end |