summaryrefslogtreecommitdiff
path: root/danger/eslint/Dangerfile
blob: 92830bd7706987ea1ded7b9c68897694bba2164e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

def get_eslint_files(files)
  files.select do |file|
    file.end_with?('.js', '.vue') &&
      File.read(file).include?('/* eslint-disable')
  end
end

eslint_candidates = get_eslint_files(helper.all_changed_files)

return if eslint_candidates.empty?

warn 'This merge request changed files with disabled eslint rules. Please consider fixing them.'

if GitlabDanger.new(helper.gitlab_helper).ci?
  markdown(<<~MARKDOWN)
    ## Disabled eslint rules

    The following files have disabled `eslint` rules. Please consider fixing them:

    * #{eslint_candidates.map { |path| "`#{path}`" }.join("\n* ")}

    Run the following command for more details

    ```
    node_modules/.bin/eslint --report-unused-disable-directives --no-inline-config \\
    #{eslint_candidates.map { |path| "  '#{path}'" }.join(" \\\n")}
    ```
  MARKDOWN
end