Skip to content

Commit 2d51af3

Browse files
committed
Update ESLint rules and pass all of them
This is done via a new script, npm run lint-is-complete, which finds any unset rules. The majority of changes are driven by preferring destructuring and spacing changes.
1 parent 3bdd8f0 commit 2d51af3

File tree

124 files changed

+1799
-923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1799
-923
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ benchmark/browser-bundle.js
44
test/worker-bundle.js
55

66
lib/jsdom/browser/default-stylesheet.js
7-
lib/jsdom/level2/style.js
87
lib/jsdom/level3/xpath.js
98

109
lib/jsdom/living/generated/**
@@ -29,3 +28,4 @@ test/to-port-to-wpts/script.js
2928
test/web-platform-tests/tests
3029
test/web-platform-tests/to-upstream/dom/nodes/Document-createComment-createTextNode.js
3130
test/web-platform-tests/to-upstream/domparsing/DOMParser-dont-upstream.html
31+
test/web-platform-tests/to-upstream/html/semantics/scripting-1/the-script-element/script-languages-dont-upstream.html

.eslintrc.json

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
},
1010
"rules": {
1111
// Possible errors
12-
"comma-dangle": ["error", "never"],
12+
"for-direction": "error",
13+
"getter-return": "error",
14+
"no-await-in-loop": "error",
15+
"no-compare-neg-zero": "error",
1316
"no-cond-assign": ["error", "except-parens"],
1417
"no-console": "error",
1518
"no-constant-condition": ["error", { "checkLoops": false }],
@@ -28,13 +31,15 @@
2831
"no-inner-declarations": "off",
2932
"no-invalid-regexp": "error",
3033
"no-irregular-whitespace": "error",
31-
"no-negated-in-lhs": "error",
3234
"no-obj-calls": "error",
35+
"no-prototype-builtins": "error",
3336
"no-regex-spaces": "error",
3437
"no-sparse-arrays": "error",
38+
"no-template-curly-in-string": "error",
3539
"no-unexpected-multiline": "error",
3640
"no-unreachable": "error",
3741
"no-unsafe-finally": "off",
42+
"no-unsafe-negation": "error",
3843
"use-isnan": "error",
3944
"valid-jsdoc": "off",
4045
"valid-typeof": "error",
@@ -43,6 +48,7 @@
4348
"accessor-pairs": "error",
4449
"array-callback-return": "error",
4550
"block-scoped-var": "off",
51+
"class-methods-use-this": "off",
4652
"complexity": "off",
4753
"consistent-return": "error",
4854
"curly": ["error", "all"],
@@ -65,6 +71,7 @@
6571
"no-extra-label": "error",
6672
"no-fallthrough": "error",
6773
"no-floating-decimal": "error",
74+
"no-global-assign": "error",
6875
"no-implicit-coercion": "error",
6976
"no-implicit-globals": "error",
7077
"no-implied-eval": "off",
@@ -76,7 +83,6 @@
7683
"no-magic-numbers": "off",
7784
"no-multi-spaces": "error",
7885
"no-multi-str": "error",
79-
"no-native-reassign": "error",
8086
"no-new": "error",
8187
"no-new-func": "error",
8288
"no-new-wrappers": "error",
@@ -86,7 +92,9 @@
8692
"no-process-env": "error",
8793
"no-proto": "error",
8894
"no-redeclare": "error",
95+
"no-restricted-properties": "off",
8996
"no-return-assign": ["error", "except-parens"],
97+
"no-return-await": "error",
9098
"no-script-url": "off",
9199
"no-self-assign": "error",
92100
"no-self-compare": "error",
@@ -98,10 +106,13 @@
98106
"no-useless-call": "error",
99107
"no-useless-concat": "error",
100108
"no-useless-escape": "error",
109+
"no-useless-return": "error",
101110
"no-void": "error",
102111
"no-warning-comments": "off",
103112
"no-with": "error",
113+
"prefer-promise-reject-errors": "error",
104114
"radix": ["error", "as-needed"],
115+
"require-await": "error",
105116
"vars-on-top": "off",
106117
"wrap-iife": ["error", "outside"],
107118
"yoda": ["error", "never"],
@@ -127,84 +138,111 @@
127138
"callback-return": "off",
128139
"global-require": "error",
129140
"handle-callback-err": "error",
141+
"no-buffer-constructor": "error",
130142
"no-mixed-requires": ["error", true],
131143
"no-new-require": "error",
132144
"no-path-concat": "error",
133145
"no-process-exit": "error",
134-
"no-restricted-imports": "off",
135146
"no-restricted-modules": "off",
136147
"no-sync": "off",
137148

138149
// Stylistic Issues
150+
"array-bracket-newline": ["error", { "multiline": true }],
139151
"array-bracket-spacing": ["error", "never"],
152+
"array-element-newline": ["off"],
140153
"block-spacing": ["error", "always"],
141154
"brace-style": ["error", "1tbs", { "allowSingleLine": false }],
142155
"camelcase": ["error", { "properties": "always" }],
156+
"capitalized-comments": "off",
157+
"comma-dangle": ["error", "never"],
143158
"comma-spacing": ["error", { "before": false, "after": true }],
144159
"comma-style": ["error", "last"],
145160
"computed-property-spacing": ["error", "never"],
146161
"consistent-this": "off",
147162
"eol-last": "error",
163+
"func-call-spacing": ["error", "never"],
164+
"func-name-matching": ["error"],
148165
"func-names": "off",
149166
"func-style": ["error", "declaration"],
167+
"function-paren-newline": ["error", "multiline"],
150168
"id-blacklist": "off",
151169
"id-length": "off",
152170
"id-match": "off",
153-
"indent": ["error", 2, { "SwitchCase": 1 }],
171+
"indent": ["error", 2, { "SwitchCase": 1, "CallExpression": {"arguments": "first"}, "FunctionExpression": {"parameters": "first"}, "ignoredNodes": ["ConditionalExpression"] }],
154172
"jsx-quotes": "off",
155173
"key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "strict" }],
156174
"keyword-spacing": ["error", { "before": true, "after": true }],
175+
"line-comment-position": "off",
157176
"linebreak-style": ["error", "unix"],
158177
"lines-around-comment": "off",
159178
"max-depth": "off",
160179
"max-len": ["error", 120, { "ignoreUrls": true }],
180+
"max-lines": "off",
161181
"max-nested-callbacks": "off",
162182
"max-params": "off",
163183
"max-statements": "off",
164184
"max-statements-per-line": ["error", { "max": 1 }],
185+
"multiline-ternary": ["error", "always-multiline"],
165186
"new-cap": ["error", { "capIsNewExceptions": ["USVString", "DOMString"] }],
166187
"new-parens": "error",
167-
"newline-after-var": "off",
168-
"newline-before-return": "off",
169188
"newline-per-chained-call": "off",
170189
"no-array-constructor": "error",
171190
"no-bitwise": "off",
172191
"no-continue": "off",
173192
"no-inline-comments": "off",
174193
"no-lonely-if": "error",
194+
"no-mixed-operators": [
195+
"error",
196+
{
197+
"groups": [
198+
["&", "|", "^", "~", "<<", ">>", ">>>"],
199+
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
200+
["&&", "||"],
201+
["in", "instanceof"]
202+
]
203+
}
204+
],
175205
"no-mixed-spaces-and-tabs": "error",
206+
"no-multi-assign": "off",
176207
"no-multiple-empty-lines": "error",
177208
"no-negated-condition": "off",
178209
"no-nested-ternary": "error",
179210
"no-new-object": "error",
180211
"no-plusplus": "off",
181212
"no-restricted-syntax": "off",
182-
"no-spaced-func": "error",
213+
"no-tabs": "error",
183214
"no-ternary": "off",
184215
"no-trailing-spaces": "error",
185216
"no-underscore-dangle": "off",
186217
"no-unneeded-ternary": "error",
187218
"no-whitespace-before-property": "error",
219+
"nonblock-statement-body-position": "error",
220+
"object-curly-newline": ["error", { "consistent": true }],
188221
"object-curly-spacing": ["error", "always"],
189222
"object-property-newline": "off",
190223
"one-var": ["error", "never"],
191224
"one-var-declaration-per-line": ["error", "initializations"],
192225
"operator-assignment": ["error", "always"],
193226
"operator-linebreak": ["error", "after"],
194227
"padded-blocks": ["error", "never"],
228+
"padding-line-between-statements": "off",
195229
"quote-props": ["error", "as-needed"],
196230
"quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }],
197231
"require-jsdoc": "off",
198232
"semi": ["error", "always"],
199233
"semi-spacing": "error",
200-
"sort-imports": "off",
234+
"semi-style": "error",
235+
"sort-keys": "off",
201236
"sort-vars": "off",
202237
"space-before-blocks": ["error", "always"],
203238
"space-before-function-paren": ["error", { "anonymous": "always", "named": "never" }],
204239
"space-in-parens": ["error", "never"],
205240
"space-infix-ops": "error",
206241
"space-unary-ops": ["error", { "words": true, "nonwords": false }],
207242
"spaced-comment": ["error", "always", { "markers": ["///"] }],
243+
"switch-colon-spacing": "error",
244+
"template-tag-spacing": "error",
245+
"unicode-bom": "error",
208246
"wrap-regex": "off",
209247

210248
// ECMAScript 6
@@ -219,18 +257,24 @@
219257
"no-dupe-class-members": "error",
220258
"no-duplicate-imports": "error",
221259
"no-new-symbol": "error",
260+
"no-restricted-imports": "off",
222261
"no-this-before-super": "error",
223262
"no-useless-computed-key": "error",
224263
"no-useless-constructor": "error",
264+
"no-useless-rename": "error",
225265
"no-var": "error",
226266
"object-shorthand": "error",
227267
"prefer-arrow-callback": "error",
228268
"prefer-const": ["error", { "ignoreReadBeforeAssign": true }],
229-
"prefer-reflect": "off",
269+
"prefer-destructuring": ["error", { "VariableDeclarator": { "array": false, "object": true }, "AssignmentExpression": { "array": false, "object": false } }, { "enforceForRenamedProperties": false }],
270+
"prefer-numeric-literals": "error",
230271
"prefer-rest-params": "off",
231272
"prefer-spread": "error",
232273
"prefer-template": "off",
233274
"require-yield": "error",
275+
"rest-spread-spacing": "error",
276+
"sort-imports": "off",
277+
"symbol-description": "error",
234278
"template-curly-spacing": ["error", "never"],
235279
"yield-star-spacing": ["error", "after"]
236280
}

benchmark/document-suite.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@ function addBenchmark(suite, benchmark) {
2020
}
2121
}
2222

23-
function benchmarkFunctions(document, options) {
24-
const setup = options.setup || noop;
25-
const fn = options.fn;
26-
const teardown = options.teardown || noop;
27-
23+
function benchmarkFunctions(document, { setup = noop, fn, teardown = noop, defer }) {
2824
return {
2925
setup() {
3026
setup.call(this, document);
3127
},
32-
fn: options.defer ?
28+
fn: defer ?
3329
function (deferred) {
3430
fn.call(this, deferred, document);
3531
} :

benchmark/path-to-suites.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = function pathToSuites(benchmarks, paths) {
1111
let suites = benchmarks;
1212

1313
for (const part of parts) {
14-
suites = suites.hasOwnProperty(part) && suites[part];
14+
suites = Object.prototype.hasOwnProperty.call(suites, part) && suites[part];
1515
if (!suites) {
1616
throw Error("Invalid suite: '" + path + "'");
1717
}

benchmark/runner.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const pathToSuites = require("./path-to-suites");
77
const benchmarks = require(".");
88
const fs = require("fs");
99
const path = require("path");
10-
const toFileUrl = require("../lib/jsdom/utils").toFileUrl;
10+
const { toFileUrl } = require("../lib/jsdom/utils");
1111

1212
const optimist = require("optimist")
1313
.usage("Run the jsdom benchmark suite")
@@ -31,8 +31,10 @@ if (optimist.argv.bundle) {
3131
bundle.bundle()
3232
.pipe(fs.createWriteStream(path.resolve(__dirname, "browser-bundle.js")))
3333
.on("finish", () => {
34-
console.info("Open the following page in Chrome to begin benchmarking:",
35-
toFileUrl(path.resolve(__dirname, "browser-runner.html")));
34+
console.info(
35+
"Open the following page in Chrome to begin benchmarking:",
36+
toFileUrl(path.resolve(__dirname, "browser-runner.html"))
37+
);
3638
});
3739
return;
3840
}

lib/jsdom/browser/Window.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const namedPropertiesWindow = require("../living/named-properties-window");
1010
const cssom = require("cssom");
1111
const postMessage = require("../living/post-message");
1212
const DOMException = require("domexception");
13-
const btoa = require("abab").btoa;
14-
const atob = require("abab").atob;
13+
const { btoa, atob } = require("abab");
1514
const idlUtils = require("../living/generated/utils");
1615
const createXMLHttpRequest = require("../living/xmlhttprequest");
1716
const createFileReader = require("../living/generated/FileReader").createInterface;
@@ -107,8 +106,7 @@ function Window(options) {
107106
if (options.virtualConsole instanceof VirtualConsole) {
108107
this._virtualConsole = options.virtualConsole;
109108
} else {
110-
throw new TypeError(
111-
"options.virtualConsole must be a VirtualConsole (from createVirtualConsole)");
109+
throw new TypeError("options.virtualConsole must be a VirtualConsole (from createVirtualConsole)");
112110
}
113111
} else {
114112
this._virtualConsole = new VirtualConsole();
@@ -386,7 +384,7 @@ function Window(options) {
386384
const nodeImpl = idlUtils.implForWrapper(node);
387385
const s = node.style;
388386
const cs = new CSSStyleDeclaration();
389-
const forEach = Array.prototype.forEach;
387+
const { forEach } = Array.prototype;
390388

391389
function setPropertiesFromRule(rule) {
392390
if (!rule.selectorText) {

lib/jsdom/browser/htmltodom.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ module.exports = class HTMLToDOM {
3333

3434
let dom;
3535
if (fragment) {
36-
const parentElement = htmlparser2Adapter.createElement(
37-
element.tagName.toLowerCase(), element.namespaceURI, []
38-
);
36+
const parentElement = htmlparser2Adapter.createElement(element.tagName.toLowerCase(), element.namespaceURI, []);
3937

4038
options.treeAdapter = htmlparser2Adapter;
4139
dom = this.parser.parseFragment(parentElement, html, options);
@@ -148,7 +146,7 @@ module.exports = class HTMLToDOM {
148146
};
149147

150148
function setChild(core, parentImpl, node) {
151-
const currentDocument = parentImpl && parentImpl._ownerDocument || parentImpl;
149+
const currentDocument = (parentImpl && parentImpl._ownerDocument) || parentImpl;
152150

153151
let newNode;
154152
let isTemplateContents = false;
@@ -184,10 +182,13 @@ function setChild(core, parentImpl, node) {
184182
newNode = currentDocument.createProcessingInstruction(node.name.substring(1), data);
185183
} else if (node.name.toLowerCase() === "!doctype") {
186184
if (node["x-name"] !== undefined) { // parse5 supports doctypes directly
187-
newNode = createDocumentTypeInternal(core, currentDocument,
185+
newNode = createDocumentTypeInternal(
186+
core,
187+
currentDocument,
188188
node["x-name"] || "",
189189
node["x-publicId"] || "",
190-
node["x-systemId"] || "");
190+
node["x-systemId"] || ""
191+
);
191192
} else {
192193
newNode = parseDocType(core, currentDocument, "<" + node.data + ">");
193194
}
@@ -204,16 +205,10 @@ function setChild(core, parentImpl, node) {
204205
if (node.attribs) {
205206
Object.keys(node.attribs).forEach(localName => {
206207
const value = node.attribs[localName];
207-
let prefix =
208-
node["x-attribsPrefix"] &&
209-
Object.prototype.hasOwnProperty.call(node["x-attribsPrefix"], localName) &&
210-
node["x-attribsPrefix"][localName] || null;
211-
const namespace =
212-
node["x-attribsNamespace"] &&
213-
Object.prototype.hasOwnProperty.call(node["x-attribsNamespace"], localName) &&
214-
node["x-attribsNamespace"][localName] || null;
208+
let prefix = getXPropForLocalName(node, "x-attribsPrefix", localName);
209+
const namespace = getXPropForLocalName(node, "x-attribsNamespace", localName);
215210
if (prefix === "xmlns" && localName === "") {
216-
// intended weirdness in node-sax, see https://github.com/isaacs/sax-js/issues/165
211+
// intended weirdness in node-sax, see https://github.com/isaacs/sax-js/issues/165
217212
localName = prefix;
218213
prefix = null;
219214
}
@@ -239,6 +234,15 @@ function setChild(core, parentImpl, node) {
239234
return newNode;
240235
}
241236

237+
function getXPropForLocalName(node, xprop, localName) {
238+
const xpropValue = node[xprop];
239+
if (xpropValue && Object.prototype.hasOwnProperty.call(xpropValue, localName)) {
240+
return xpropValue[localName] || null;
241+
}
242+
243+
return null;
244+
}
245+
242246
const HTML5_DOCTYPE = /<!doctype html>/i;
243247
const PUBLIC_DOCTYPE = /<!doctype\s+([^\s]+)\s+public\s+"([^"]+)"\s+"([^"]+)"/i;
244248
const SYSTEM_DOCTYPE = /<!doctype\s+([^\s]+)\s+system\s+"([^"]+)"/i;

0 commit comments

Comments
 (0)