Skip to content

Commit

Permalink
Make javascript linting task compatible with eslint 9+
Browse files Browse the repository at this point in the history
  • Loading branch information
ushkarev committed Jun 3, 2024
1 parent 2ccbf61 commit 5ccf629
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ npm-debug.log
package-lock.json

# app-specific
.eslintrc.json
/eslint.config.cjs
.sass-lint.yml
mtp_common/assets/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export var YearFieldCompletion = {
init: function (selector) {
$(selector || this.selector).blur(function () {
var $input = $(this);
var currentYear = (new Date()).getFullYear();
var currentYear = new Date().getFullYear();
var century = 100 * Math.floor(currentYear / 100);
var eraBoundary = parseInt($input.data('era-boundary'), 10);
if (isNaN(eraBoundary)) {
Expand Down
2 changes: 1 addition & 1 deletion mtp_common/build_tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def lint_config(context: Context):
"""
Generates javasript and stylesheet linting configuration files
"""
context.write_template('eslintrc.json', path='.eslintrc.json')
context.write_template('eslint.config.cjs')
context.write_template('sass-lint.yml', path='.sass-lint.yml')


Expand Down
73 changes: 73 additions & 0 deletions mtp_common/templates/mtp_common/build_tasks/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
var globals = require('globals');
var eslintJs = require('@eslint/js');

module.exports = [
eslintJs.configs.recommended,
{
languageOptions: {
sourceType: 'module',
globals: {
...globals.commonjs,
...globals.es2015,
...globals.browser,
...globals.jquery,
django: 'readonly',
Sentry: 'readonly',
},
},
rules: {
'indent': ['error', 2, {SwitchCase: 1}],
'complexity': ['error', 20],
'eol-last': ['error'],
'max-len': ['error', 120],
'radix': ['error', 'always'],
'semi': ['error'],
'semi-spacing': ['error'],
'semi-style': ['error', 'last'],

'array-bracket-spacing': ['warn'],
'brace-style': ['warn', '1tbs'],
'camelcase': ['warn'],
'comma-spacing': ['warn'],
'comma-style': ['warn'],
'consistent-return': ['warn'],
'curly': ['warn', 'all'],
'eqeqeq': ['warn'],
'func-call-spacing': ['warn'],
'guard-for-in': ['warn'],
'init-declarations': ['warn'],
'key-spacing': ['warn'],
'keyword-spacing': ['warn'],
'linebreak-style': ['warn', 'unix'],
'quotes': ['warn', 'single'],
'no-eval': ['warn'],
'no-extra-parens': ['warn'],
'no-implicit-coercion': ['warn'],
'no-implicit-globals': ['warn'],
'no-implied-eval': ['warn'],
'no-labels': ['warn'],
'no-lone-blocks': ['warn'],
'no-lonely-if': ['warn'],
'no-multi-spaces': ['warn'],
'no-multi-str': ['warn'],
'no-return-assign': ['warn'],
'no-self-compare': ['warn'],
'no-trailing-spaces': ['warn'],
'no-unsafe-negation': ['warn'],
'no-unused-expressions': ['warn'],
'no-use-before-define': ['warn'],
'no-useless-call': ['warn'],
'no-useless-concat': ['warn'],
'no-useless-escape': ['warn'],
'no-void': ['warn'],
'no-whitespace-before-property': ['warn'],
'no-with': ['warn'],
'object-property-newline': ['warn'],
'space-before-function-paren': ['warn'],
'space-infix-ops': ['warn'],
'space-unary-ops': ['warn'],
'spaced-comment': ['warn'],
'wrap-iife': ['warn'],
},
},
];
70 changes: 0 additions & 70 deletions mtp_common/templates/mtp_common/build_tasks/eslintrc.json

This file was deleted.

2 changes: 2 additions & 0 deletions mtp_common/templates/mtp_common/build_tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"license": "MIT",
"devDependencies": {
"browser-sync": "~3.0",
"@eslint/js": "~9.4",
"eslint": "~9.4",
"globals": "~15.3",
"sass-lint": "~1.13.1"
},
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
},
"license": "MIT",
"devDependencies": {
"@eslint/js": "~9.4",
"eslint": "~9.4",
"globals": "~15.3",
"sass-lint": "~1.13.1"
}
}

0 comments on commit 5ccf629

Please sign in to comment.