Skip to content

Commit e854320

Browse files
bernardobelchiorcburgmer
authored andcommitted
Migrate from JSHint to ESLint
1 parent 667ab02 commit e854320

File tree

8 files changed

+725
-306
lines changed

8 files changed

+725
-306
lines changed

Gruntfile.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*global module:false*/
21
module.exports = function (grunt) {
32
grunt.initConfig({
43
pkg: grunt.file.readJSON("package.json"),
@@ -196,20 +195,21 @@ module.exports = function (grunt) {
196195
},
197196
watch: {
198197
files: ["src/*.js", "test/specs/*.js"],
199-
tasks: ["jshint", "jasmine"],
198+
tasks: ["eslint", "jasmine"],
200199
},
201-
jshint: {
202-
all: ["src/**/*.js", "test/**/*.js", "*.js"],
200+
eslint: {
203201
options: {
204-
jshintrc: true,
202+
overrideConfigFile: "eslint.config.js",
203+
quiet: true,
205204
},
205+
target: ["src/**/*.js", "test/**/*.js", "Gruntfile.js"],
206206
},
207207
});
208208

209209
grunt.loadNpmTasks("grunt-contrib-concat");
210210
grunt.loadNpmTasks("grunt-contrib-connect");
211211
grunt.loadNpmTasks("grunt-contrib-jasmine");
212-
grunt.loadNpmTasks("grunt-contrib-jshint");
212+
grunt.loadNpmTasks("grunt-eslint");
213213
grunt.loadNpmTasks("grunt-contrib-uglify");
214214
grunt.loadNpmTasks("grunt-contrib-watch");
215215
grunt.loadNpmTasks("grunt-contrib-clean");
@@ -222,7 +222,7 @@ module.exports = function (grunt) {
222222
"browserify:inlineresources",
223223
]);
224224

225-
grunt.registerTask("test", ["jshint", "connect", "jasmine"]);
225+
grunt.registerTask("test", ["eslint", "connect", "jasmine"]);
226226

227227
grunt.registerTask("build", [
228228
"concat:one",

eslint.config.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
const globals = require("globals");
2+
const { defineConfig, globalIgnores } = require("eslint/config");
3+
4+
const commonRules = {
5+
// curly: true
6+
curly: "error",
7+
// eqeqeq: true + eqnull: true
8+
eqeqeq: ["error", "always", { null: "ignore" }],
9+
// immed: true (wrap immediately invoked function expressions)
10+
"wrap-iife": ["error", "any"],
11+
// latedef: true
12+
"no-use-before-define": [
13+
"error",
14+
{ functions: true, classes: true, variables: true },
15+
],
16+
// newcap: true
17+
"new-cap": "error",
18+
// noarg: true
19+
"no-caller": "error",
20+
// undef: true
21+
"no-undef": "error",
22+
// trailing: true
23+
"no-trailing-spaces": "error",
24+
// laxbreak: true - allow line breaks before operators
25+
"operator-linebreak": "off",
26+
};
27+
28+
module.exports = defineConfig([
29+
globalIgnores([
30+
"test/performance_test_pages/**/*.js",
31+
"test/fixtures/*.js",
32+
]),
33+
{
34+
files: ["src/**/*.js"],
35+
languageOptions: {
36+
ecmaVersion: 2018,
37+
sourceType: "script",
38+
globals: {
39+
...globals.browser,
40+
util: "readonly",
41+
proxies: "readonly",
42+
documentUtil: "readonly",
43+
documentHelper: "readonly",
44+
browser: "readonly",
45+
svg2image: "readonly",
46+
document2svg: "readonly",
47+
rasterize: "readonly",
48+
// external dependencies
49+
url: "readonly",
50+
xmlserializer: "readonly",
51+
sanedomparsererror: "readonly",
52+
inlineresources: "readonly",
53+
},
54+
},
55+
rules: {
56+
...commonRules,
57+
// unused: true - but allow exported module-level vars
58+
"no-unused-vars": [
59+
"error",
60+
{
61+
varsIgnorePattern:
62+
"^(util|proxies|documentUtil|documentHelper|browser|svg2image|document2svg|rasterize|rasterizeHTML)$",
63+
},
64+
],
65+
// strict: true
66+
strict: ["error", "function"],
67+
},
68+
},
69+
{
70+
files: ["test/**/*.js"],
71+
languageOptions: {
72+
ecmaVersion: 2018,
73+
sourceType: "script",
74+
globals: {
75+
...globals.browser,
76+
...globals.node,
77+
Promise: true,
78+
// console etc from devel
79+
console: true,
80+
alert: true,
81+
// jasmine globals
82+
jasmine: true,
83+
describe: true,
84+
it: true,
85+
xit: true,
86+
beforeEach: true,
87+
afterEach: true,
88+
expect: true,
89+
fail: true,
90+
spyOn: true,
91+
// project test helpers
92+
ifNotInWebkitOrBlinkIt: true,
93+
testHelper: true,
94+
diffHelper: true,
95+
// project globals
96+
util: true,
97+
proxies: true,
98+
documentUtil: true,
99+
documentHelper: true,
100+
browser: true,
101+
svg2image: true,
102+
document2svg: true,
103+
rasterize: true,
104+
rasterizeHTML: true,
105+
imagediff: true,
106+
// external dependencies
107+
inlineresources: true,
108+
isEqual: true,
109+
},
110+
},
111+
rules: {
112+
...commonRules,
113+
// unused: true - allow unused function parameters (common in test callbacks)
114+
"no-unused-vars": ["error", { args: "none" }],
115+
// strict: true - disabled in test files as they have mixed patterns
116+
strict: "off",
117+
},
118+
},
119+
{
120+
files: ["Gruntfile.js"],
121+
languageOptions: {
122+
ecmaVersion: 2018,
123+
sourceType: "script",
124+
globals: {
125+
...globals.node,
126+
module: true,
127+
},
128+
},
129+
rules: {
130+
...commonRules,
131+
"no-unused-vars": "error",
132+
strict: "off",
133+
},
134+
},
135+
]);

0 commit comments

Comments
 (0)