diff --git a/.ruby-style.yml b/.ruby-style.yml index e130ac532..62b587f53 100644 --- a/.ruby-style.yml +++ b/.ruby-style.yml @@ -251,6 +251,14 @@ Style/MethodName: SupportedStyles: - snake_case - camelCase +Style/MultilineMethodCallIndentation: + Description: Checks indentation of method calls with the dot operator + that span more than one line. + Enabled: true + EnforcedStyle: indented + SupportedStyles: + - aligned + - indented Style/MultilineOperationIndentation: Description: Checks indentation of binary operations that span more than one line. Enabled: true diff --git a/app/models/linter/eslint.rb b/app/models/linter/eslint.rb index eccaf92f2..dde509904 100644 --- a/app/models/linter/eslint.rb +++ b/app/models/linter/eslint.rb @@ -10,7 +10,7 @@ def file_included?(commit_file) private def jsignore - @jsignore ||= JsIgnore.new(hound_config, IGNORE_FILENAME) + @jsignore ||= JsIgnore.new(name, hound_config, IGNORE_FILENAME) end end end diff --git a/app/models/linter/jshint.rb b/app/models/linter/jshint.rb index 8ca284a20..1c8288c6d 100644 --- a/app/models/linter/jshint.rb +++ b/app/models/linter/jshint.rb @@ -10,7 +10,7 @@ def file_included?(commit_file) private def jsignore - @jsignore ||= JsIgnore.new(hound_config, IGNORE_FILENAME) + @jsignore ||= JsIgnore.new(name, hound_config, IGNORE_FILENAME) end end end diff --git a/lib/js_ignore.rb b/lib/js_ignore.rb index 09f0671c7..50ef95c9d 100644 --- a/lib/js_ignore.rb +++ b/lib/js_ignore.rb @@ -1,10 +1,7 @@ class JsIgnore DEFAULT_EXCLUDED_PATHS = %w(vendor/*).freeze - def initialize(hound_config, ignore_filename) - @hound_config = hound_config - @ignore_filename = ignore_filename - end + attr_private_initialize :linter_name, :hound_config, :default_filename def file_included?(commit_file) excluded_paths.none? do |pattern| @@ -14,8 +11,6 @@ def file_included?(commit_file) private - attr_reader :hound_config, :ignore_filename - def excluded_paths ignored_paths.presence || DEFAULT_EXCLUDED_PATHS end @@ -31,7 +26,7 @@ def ignored_paths def ignore_filename @ignore_filename ||= hound_config. content. - fetch("javascript", {}). - fetch("ignore_file", ignore_filename) + fetch(linter_name, {}). + fetch("ignore_file", default_filename) end end diff --git a/spec/lib/js_ignore_spec.rb b/spec/lib/js_ignore_spec.rb index ec42e7fac..1b85f0da1 100644 --- a/spec/lib/js_ignore_spec.rb +++ b/spec/lib/js_ignore_spec.rb @@ -5,23 +5,31 @@ describe "#file_included?" do context "file is in excluded file list" do it "returns false" do - jsignore = build_js_ignore(["foo.js"]) - commit_file = double("CommitFile", filename: "foo.js") + jsignore = build_js_ignore("javascript", "foo/*") + commit_file = double("CommitFile", filename: "foo/bar.js") expect(jsignore.file_included?(commit_file)).to eq false end + + context "with a different linter" do + it "returns false" do + jsignore = build_js_ignore("eslint", "foo/*") + commit_file = instance_double("CommitFile", filename: "foo/bar.js") + + expect(jsignore.file_included?(commit_file)).to be false + end + end end context "file is not excluded" do it "returns true" do - jsignore = build_js_ignore(["foo.js"]) - commit_file = double("CommitFile", filename: "bar.js") + jsignore = build_js_ignore("javascript", "foo/*") + commit_file = double("CommitFile", filename: "foo.js") expect(jsignore.file_included?(commit_file)).to eq true end it "matches a glob pattern" do - jsignore = build_js_ignore(["app/assets/javascripts/*.js", "vendor/*"]) commit_file1 = double( "CommitFile", filename: "app/assets/javascripts/bar.js", @@ -30,17 +38,34 @@ "CommitFile", filename: "vendor/assets/javascripts/foo.js", ) + ignore_file_content = <<~TEXT + app/assets/javascripts/*.js\n + vendor/* + TEXT + jsignore = build_js_ignore("javascript", ignore_file_content) expect(jsignore.file_included?(commit_file1)).to be false expect(jsignore.file_included?(commit_file2)).to be false end end - def build_js_ignore(paths) - jsignore = JsIgnore.new({}, ".jsignore") - allow(jsignore).to receive(:ignored_paths).and_return(paths) + def build_js_ignore(linter, content) + hound_config = build_hound_config(linter, ".jsignore", content) + + JsIgnore.new("javascript", hound_config, ".jsignore") + end + + def build_hound_config(linter, ignore_filename, content) + config_content = { + linter => { + "ignore_file" => ignore_filename, + }, + } + commit = instance_double("Commit") + allow(commit).to receive(:file_content).with(ignore_filename). + and_return(content) - jsignore + instance_double("HoundConfig", content: config_content, commit: commit) end end end