Skip to content

Commit

Permalink
Use eslint directly, update to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jun 10, 2024
1 parent 5c86193 commit 5c6ad69
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 239 deletions.
105 changes: 0 additions & 105 deletions .eslintrc.js

This file was deleted.

11 changes: 0 additions & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ module.exports = function (grunt) {
// Project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
eslint: {
files: [
'Gruntfile.js',
'service-worker.js',
'src/**/*.js',
'!src/utils/modernizr.js'
]
},
copy: {
dev: {
src: 'index.html',
Expand Down Expand Up @@ -67,11 +59,8 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-eslint');

// Task to run tests
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('test', ['eslint']);
grunt.registerTask('start', ['connect:prod', 'watch']);
grunt.registerTask('dev', ['copy:dev', 'connect:dev', 'watch']);
};
114 changes: 114 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import globals from 'globals';
import js from '@eslint/js';
import stylisticJs from '@stylistic/eslint-plugin-js';

export default [
js.configs.recommended,
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.jquery,
dwv: 'readonly',
},
},
plugins: {
'@stylistic/js': stylisticJs
},
rules: {
// require triple equal
// https://eslint.org/docs/rules/eqeqeq
eqeqeq: 'error',
// force using curly braces
// https://eslint.org/docs/rules/curly
curly: 'error',

// formatting rules

// force semi colon
// https://eslint.style/rules/js/semi
'@stylistic/js/semi': ['error'],
// force 2 space indent (default: 4)
// https://eslint.style/rules/js/indent
'@stylistic/js/indent': ['error', 2],
// force single quotes (default 'double')
// https://eslint.style/rules/js/quotes
'@stylistic/js/quotes': ['error', 'single'],
// no space for named functions (default 'always')
// https://eslint.style/rules/js/space-before-function-paren
'@stylistic/js/space-before-function-paren': ['error', {named: 'never'}],
// newline at object curly
// https://eslint.style/rules/js/object-curly-newline
'@stylistic/js/object-curly-newline': ['error', {'consistent': true}],
// newline at object properties
// https://eslint.style/rules/js/object-property-newline
'@stylistic/js/object-property-newline': [
'error', {'allowAllPropertiesOnSameLine': true}
],
// newline at array brackets
// https://eslint.style/rules/js/array-bracket-newline
'@stylistic/js/array-bracket-newline': ['error', 'consistent'],
// newline at array elements (default: always)
// https://eslint.style/rules/js/array-element-newline
'@stylistic/js/array-element-newline': ['error', 'consistent'],
// force 'one true brace style' (1tbs)
// https://eslint.style/rules/js/brace-style
'@stylistic/js/brace-style': 'error',
// give error for long lines (default: 80)
// https://eslint.style/rules/js/max-len
'@stylistic/js/max-len': [
'error', {'ignoreRegExpLiterals': true, 'ignoreUrls': true}
],
// spaces in parenthesis (default: never)
// https://eslint.style/rules/js/space-in-parens
'@stylistic/js/space-in-parens': 'error',
// space before blocks
// https://eslint.style/rules/js/space-before-blocks
'@stylistic/js/space-before-blocks': 'error',
// spaces inside brackets (default: never)
// https://eslint.style/rules/js/array-bracket-spacing
'@stylistic/js/array-bracket-spacing': 'error',
// spaces in curly (default: never)
// https://eslint.style/rules/js/object-curly-spacing
'@stylistic/js/object-curly-spacing': 'error',
// no space in computed properties (default: never)
// https://eslint.style/rules/js/computed-property-spacing
'@stylistic/js/computed-property-spacing': 'error',
// spaces around comma (default: {"before": false, "after": true})
// https://eslint.style/rules/js/comma-spacing
'@stylistic/js/comma-spacing': 'error',
// space around unary operator
// https://eslint.style/rules/js/space-unary-ops
'@stylistic/js/space-unary-ops': 'error',
// space around operator
// https://eslint.style/rules/js/space-infix-ops
'@stylistic/js/space-infix-ops': 'error',
// space around keywords (default: {'before': true, 'after': true})
// https://eslint.style/rules/js/keyword-spacing
'@stylistic/js/keyword-spacing': 'error',
// no space before function call (default: never)
// https://eslint.style/rules/js/function-call-spacing
'@stylistic/js/func-call-spacing': 'error',
// spacing around colon
// (default: {'beforeColon': false, 'afterColon': true})
// https://eslint.style/rules/js/key-spacing
'@stylistic/js/key-spacing': 'error',
// spacing around semi-colon
// https://eslint.style/rules/js/semi-spacing
'@stylistic/js/semi-spacing': 'error',
// no trailing spaces
// https://eslint.style/rules/js/no-trailing-spaces
'@stylistic/js/no-trailing-spaces': 'error',
// no multi spaces
// https://eslint.style/rules/js/no-multi-spaces
'@stylistic/js/no-multi-spaces': 'error',
// no space for named functions (default {'max': 2})
// https://eslint.style/rules/js/no-multiple-empty-lines
'@stylistic/js/no-multiple-empty-lines': 'error',
// linebreak after operator
// https://eslint.style/rules/js/operator-linebreak
'@stylistic/js/operator-linebreak': 'error'
},
}
];
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
"nprogress": "^0.2.0"
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"@stylistic/eslint-plugin-js": "^2.1.0",
"eslint": "^9.4.0",
"globals": "^15.4.0",
"grunt": "^1.4.0",
"grunt-cli": "^1.4.2",
"grunt-contrib-connect": "^4.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-eslint": "^24.0.0"
"grunt-contrib-watch": "^1.1.0"
},
"scripts": {
"start": "grunt start",
"dev": "grunt dev",
"lint": "grunt lint",
"test": "grunt test --verbose"
"lint": "eslint 'src/**/*.js' '*.js'"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dwv-jqmobile is not certified for diagnostic use. Released under GNU GPL-3.0 lic

- `install`: install dependencies
- `start`: serve at localhost:8080 with live reload
- `test`: run unit tests
- `lint`: run file linting
- `dev`: serve a developement version at localhost:8080 with live reload

## Steps to run the viewer from scratch
Expand Down
Loading

0 comments on commit 5c6ad69

Please sign in to comment.