diff --git a/config/eslint.js b/config/eslint.js index b4d0429e4a..cf9c2ff086 100644 --- a/config/eslint.js +++ b/config/eslint.js @@ -1,8 +1,10 @@ const globals = require("globals"); const js = require("@eslint/js"); +const erb = require("eslint-plugin-erb"); module.exports = [ js.configs.recommended, + erb.configs.recommended, { languageOptions: { ecmaVersion: 2021, @@ -20,6 +22,15 @@ module.exports = [ updateLinks: "readonly" } }, + linterOptions: { + // The "unused disable directive" is set to "warn" by default. + // For the ERB plugin to work correctly, you must disable + // this directive to avoid issues described here + // https://github.com/eslint/eslint/discussions/18114 + // If you're using the CLI, you might also use the following flag: + // --report-unused-disable-directives-severity=off + reportUnusedDisableDirectives: "off" + }, rules: { "accessor-pairs": "error", "array-bracket-newline": ["error", "consistent"], diff --git a/lib/tasks/eslint.rake b/lib/tasks/eslint.rake index 790ef150d6..27b550e40b 100644 --- a/lib/tasks/eslint.rake +++ b/lib/tasks/eslint.rake @@ -10,7 +10,7 @@ end def js_files Rails.application.assets.each_file.select do |file| - file.ends_with?(".js") && !file.match?(%r{/(gems|vendor|i18n|node_modules)/}) + (file.ends_with?(".js") || file.ends_with?(".js.erb")) && !file.match?(%r{/(gems|vendor|i18n|node_modules)/}) end end diff --git a/package.json b/package.json index 0edf11d8de..2e7dd7e352 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "openstreetmap", "private": true, "dependencies": { + "eslint-plugin-erb": "^2.1.0", "jquery-simulate": "^1.0.2", "js-cookie": "^3.0.0", "leaflet": "^1.8.0", diff --git a/yarn.lock b/yarn.lock index 684bbac399..d84b1961ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -259,6 +259,11 @@ eslint-formatter-compact@^8.40.0: resolved "https://registry.yarnpkg.com/eslint-formatter-compact/-/eslint-formatter-compact-8.40.0.tgz#d7455b2d75fd70e8c0e7a98a5e189f168e9dfe2d" integrity sha512-cwGUs113TgmTQXecx5kfRjB7m0y2wkDLSadPTE2pK6M/wO4N8PjmUaoWOFNCP9MHgsiZwgqd5bZFnDCnszC56Q== +eslint-plugin-erb@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-erb/-/eslint-plugin-erb-2.1.1.tgz#8a0a6c2bcaf3a8573c381b595969145aff93cfc6" + integrity sha512-AhznaVwRpQqR8NADjN4SZnKNbaIdAbGxTjCg6cj3UhwGyQOUJ6kXwhYrl1LYrGDNx7Ouyd8xuEG7wepFZyPgFw== + eslint-scope@^8.2.0: version "8.2.0" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-8.2.0.tgz#377aa6f1cb5dc7592cfd0b7f892fd0cf352ce442"