diff --git a/.eslintrc.js b/.eslintrc.js index b62b93d8ba..855c45f454 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -76,7 +76,8 @@ module.exports = { sourceType: 'module' }, env: { - browser: true, + // do not access global window properties without going through window + browser: false, es6: true }, globals: { @@ -95,7 +96,9 @@ module.exports = { parserOptions: { sourceType: 'module' }, - env: {}, + env: { + browser: false + }, globals: {}, rules: { 'func-names': [2, 'as-needed'], @@ -103,6 +106,19 @@ module.exports = { 'no-use-before-define': 'off' } }, + { + // polyfills are mostly copy-pasted from sources so we don't control their styling + files: ['lib/core/utils/pollyfills.js'], + env: { + browser: false + }, + rules: { + 'func-names': 0, + 'no-bitwise': 0, + curly: 0, + eqeqeq: 0 + } + }, { files: ['test/act-rules/**/*.js', 'test/aria-practices/**/*.js'], env: { diff --git a/lib/commons/color/get-background-stack.js b/lib/commons/color/get-background-stack.js index a37833eb9f..87225e2b5d 100644 --- a/lib/commons/color/get-background-stack.js +++ b/lib/commons/color/get-background-stack.js @@ -12,7 +12,7 @@ import reduceToElementsBelowFloating from '../dom/reduce-to-elements-below-float * @return {Boolean} */ function isInlineDescendant(node, descendant) { - const CONTAINED_BY = Node.DOCUMENT_POSITION_CONTAINED_BY; + const CONTAINED_BY = window.Node.DOCUMENT_POSITION_CONTAINED_BY; // eslint-disable-next-line no-bitwise if (!(node.compareDocumentPosition(descendant) & CONTAINED_BY)) { return false; diff --git a/lib/core/utils/dq-element.js b/lib/core/utils/dq-element.js index 4e5d0ffc28..db1c5f65bb 100644 --- a/lib/core/utils/dq-element.js +++ b/lib/core/utils/dq-element.js @@ -20,8 +20,8 @@ function getSource(element) { return ''; } var source = element.outerHTML; - if (!source && typeof XMLSerializer === 'function') { - source = new XMLSerializer().serializeToString(element); + if (!source && typeof window.XMLSerializer === 'function') { + source = new window.XMLSerializer().serializeToString(element); } return truncate(source || ''); } diff --git a/lib/core/utils/parse-crossorigin-stylesheet.js b/lib/core/utils/parse-crossorigin-stylesheet.js index 1a504216ba..3ec44fa526 100644 --- a/lib/core/utils/parse-crossorigin-stylesheet.js +++ b/lib/core/utils/parse-crossorigin-stylesheet.js @@ -26,7 +26,7 @@ function parseCrossOriginStylesheet( importedUrls.push(url); return new Promise((resolve, reject) => { - const request = new XMLHttpRequest(); + const request = new window.XMLHttpRequest(); request.open('GET', url); request.timeout = constants.preload.timeout; diff --git a/lib/core/utils/pollyfills.js b/lib/core/utils/pollyfills.js index fe1de7f354..6829b80dc8 100644 --- a/lib/core/utils/pollyfills.js +++ b/lib/core/utils/pollyfills.js @@ -1,4 +1,3 @@ -/* eslint-disable */ /* These polyfills came directly from the ES Specification itself Contained within: @@ -348,8 +347,8 @@ if (!Array.prototype.flat) { // linked from MDN docs on isConnected // @see https://gist.github.com/eligrey/f109a6d0bf4efe3461201c3d7b745e8f -if (window.Node && !('isConnected' in Node.prototype)) { - Object.defineProperty(Node.prototype, 'isConnected', { +if (window.Node && !('isConnected' in window.Node.prototype)) { + Object.defineProperty(window.Node.prototype, 'isConnected', { get() { return ( !this.ownerDocument ||