From 92635ba7211492408261cc7bae3b356c0dc4288f Mon Sep 17 00:00:00 2001 From: JFH Date: Sat, 1 Aug 2020 01:23:28 +0200 Subject: [PATCH] restore all eslint rules --- .eslintrc.js | 214 +++++++++++++++++- cypress/integration/ui/accessibility.js | 11 +- cypress/integration/unit/draw.js | 1 + cypress/integration/unit/test1.js | 1 + cypress/integration/unit/utilities-bbox.js | 1 + .../integration/unit/utilities-performance.js | 1 + cypress/integration/unit/utilities.js | 1 + cypress/plugins/main.js | 1 - cypress/support/assert-close.js | 1 + docs/jsdoc-config.js | 1 + package.json | 2 +- rollup-config.config.js | 2 - src/editor/svgicons/jQuery.svgIcons.js | 2 +- 13 files changed, 224 insertions(+), 15 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7dc18055..832a1d27 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { extends: ['ash-nazg/sauron-node'], parserOptions: { - "ecmaVersion": 2020, + ecmaVersion: 2020, sourceType: 'module' }, env: { @@ -51,7 +51,7 @@ module.exports = { 'Promise.all', // 'Set', 'Uint8Array', - 'URL', + 'URL' // 'URL.createObjectURL', // 'XMLSerializer', // 'XMLHttpRequest', @@ -107,7 +107,11 @@ module.exports = { 'unicorn/prefer-string-slice': 'off', 'default-case': 'off', 'require-unicode-regexp': 'off', - 'max-len': ['warn', { 'ignoreComments': true, 'code': 130 }], // 130 is too much but too many occurences + 'max-len': + [ + 'warn', + {ignoreComments: true, code: 130} + ], // 130 is too much but too many occurences 'unicorn/prefer-query-selector': 'off', 'unicorn/no-fn-reference-in-iterator': 'off', 'unicorn/prefer-node-append': 'off', @@ -117,8 +121,8 @@ module.exports = { 'compat/compat': 'error', 'consistent-this': 'off', 'import/no-anonymous-default-export': 'off', - 'node/no-unsupported-features/node-builtins': 'warn', - 'prefer-exponentiation-operator': 'warn' + 'node/no-unsupported-features/node-builtins': 'warn', + 'prefer-exponentiation-operator': 'warn' }, overrides: [ // Locales have no need for importing outside of SVG-Edit @@ -132,6 +136,206 @@ module.exports = { 'import/no-anonymous-default-export': 'off', 'max-len': 'off' } + }, + // These browser files don't do importing or requiring + { + files: [ + 'src/editor/svgpathseg.js', + 'src/editor/touch.js', + 'src/editor/typedefs.js', + 'src/editor/redirect-on-no-module-support.js', + 'src/editor/extensions/imagelib/index.js', + 'src/external/dom-polyfill/dom-polyfill.js', + 'screencasts/svgopen2010/script.js' + ], + rules: { + 'import/unambiguous': ['off'] + } + }, + { + files: ['**/*.html', 'screencasts/**'], + globals: { + root: 'off' + }, + settings: { + polyfills: [ + 'document.querySelector', + 'history', + 'history.pushState', + 'history.replaceState', + 'location.hash', + 'navigator', + 'Number.parseFloat', + 'Number.parseInt', + 'Number.isNaN' + ] + }, + rules: { + 'import/unambiguous': 'off' + } + }, + { + files: ['.eslintrc.js', '.ncurc.js', 'tools/mochawesome-cli.js'], + extends: [ + 'ash-nazg/sauron-node-script' + ] + }, + // Our Markdown rules (and used for JSDoc examples as well, by way of + // our use of `jsdoc/check-examples` within `ash-nazg`) + { + files: ['**/*.md'], + settings: { + polyfills: [ + // Tutorials + 'console', + 'location.href' + ] + }, + rules: { + // Todo: Figure out why this is not enough to disable warning + // for examples in my environment (but it is in others') + // Used in examples of assert-close.js plugin + 'mocha-cleanup/no-assertions-outside-it': 'off', + 'eslint-comments/no-unused-disable': 'warn', + 'eol-last': ['off'], + 'no-console': ['off'], + 'no-undef': ['off'], + 'no-unused-vars': ['warn'], + 'padded-blocks': ['off'], + 'import/unambiguous': ['off'], + 'import/no-unresolved': ['off'], + 'node/no-missing-import': ['off'], + 'no-multi-spaces': 'off', + 'sonarjs/no-all-duplicated-branches': 'off', + 'node/no-unpublished-import': ['error', { + allowModules: ['@cypress/fiddle'] + }], + 'no-alert': 'off', + // Disable until may fix https://github.com/gajus/eslint-plugin-jsdoc/issues/211 + indent: 'off' + } + }, + { + // As consumed by jsdoc, cannot be expressed as ESM + files: ['docs/jsdoc-config.js'], + parserOptions: { + sourceType: 'script' + }, + globals: { + module: false + }, + rules: { + 'import/no-commonjs': 'off', + strict: 'off' + } + }, + { + files: ['cypress/plugins/index.js'], + extends: [ + 'ash-nazg/sauron-node-script' + ] + }, + { + files: ['cypress/**'], + extends: [ + 'plugin:cypress/recommended', + 'plugin:mocha/recommended', + 'plugin:mocha-cleanup/recommended-no-limits', + 'plugin:@fintechstudios/chai-as-promised/recommended', + 'plugin:chai-expect-keywords/recommended', + 'plugin:chai-expect/recommended', + 'plugin:chai-friendly/recommended' + ], + env: { + node: true + }, + settings: { + polyfills: [ + 'console', + 'Date.now', + 'document.body', + 'document.createElementNS', + 'document.head', + 'DOMParser', + 'Number.isNaN', + 'Object.keys', + 'Object.entries', + 'Promise' + ] + }, + rules: { + // These errors are caused in Cypress files if user has not + // yet instrumented code; need to reinvestigate why we had to + // instrument separately from nyc mocha + 'import/no-unresolved': ['error', {ignore: ['/instrumented/']}], + 'node/no-missing-import': 'off', + 'jsdoc/check-examples': 'off', + 'chai-expect-keywords/no-unsupported-keywords': [ + 'error', { + allowChaiDOM: true + } + ], + // Would be good but seems necessary due to some bugs in Cypress + // in detecting visibility + // 'cypress/no-force': 0, + // Good but would be difficult to enforce (and data-* may not be less + // brittle than IDs/classes anyways) + // 'cypress/require-data-selectors': 0, + 'cypress/assertion-before-screenshot': 2, + + // Conflicts with Cypress `should` + 'mocha-cleanup/invalid-assertions': 0, + + // Might see about working around to avoid the option limitation, + // but convenient + 'mocha-cleanup/no-expressions-in-assertions': ['error', { + replacementsOnly: true + }], + + // Too oppressive when planning to extend a section + 'mocha/no-hooks-for-single-case': 0, + + // Would be good to enable but needs some refactoring + 'mocha/no-setup-in-describe': 0, + 'mocha-cleanup/no-outside-declaration': 0, + + // Useful to ensure allowing `this.timeout()`, etc., but a + // little oppressive + 'mocha/no-mocha-arrows': 0, + // Useful if enabling the regular `prefer-arrow-callback` + // 'mocha/prefer-arrow-callback': 2 + + 'jsdoc/require-jsdoc': 0, + 'no-console': 0, + 'import/unambiguous': 0 + } + }, + { + // Node files + files: [ + 'docs/jsdoc-config.js', + 'build/build-html.js', + 'rollup.config.js', 'rollup-config.config.js' + ], + env: { + node: true + }, + settings: { + polyfills: [ + 'console', + 'Promise.resolve' + ] + }, + globals: { + require: true + }, + rules: { + // We can't put Rollup in npmignore or user can't get access, + // and we have too many modules to add to `peerDependencies` + // so this rule can know them to be available, so we instead + // disable + 'node/no-unpublished-import': 'off' + } } ] }; diff --git a/cypress/integration/ui/accessibility.js b/cypress/integration/ui/accessibility.js index 446a32a1..b1363b03 100644 --- a/cypress/integration/ui/accessibility.js +++ b/cypress/integration/ui/accessibility.js @@ -29,11 +29,12 @@ describe('UI - Accessibility', function () { {}, { rules: { - 'label-title-only': { enabled: false }, - 'page-has-heading-one': { enabled: false }, - 'region': { enabled: false }, - 'scrollable-region-focusable': { enabled: false }, + 'label-title-only': {enabled: false}, + 'page-has-heading-one': {enabled: false}, + region: {enabled: false}, + 'scrollable-region-focusable': {enabled: false} } - }); + } + ); }); }); diff --git a/cypress/integration/unit/draw.js b/cypress/integration/unit/draw.js index b7207b58..750491a2 100644 --- a/cypress/integration/unit/draw.js +++ b/cypress/integration/unit/draw.js @@ -20,6 +20,7 @@ describe('draw.Drawing', function () { const PATH_ATTR = { // clone will convert relative to absolute, so the test for equality fails. // d: 'm7.38867,57.38867c0,-27.62431 22.37569,-50 50,-50c27.62431,0 50,22.37569 50,50c0,27.62431 -22.37569,50 -50,50c-27.62431,0 -50,-22.37569 -50,-50z', + // eslint-disable-next-line max-len d: 'M7.389,57.389C7.389,29.764 29.764,7.389 57.389,7.389C85.013,7.389 107.389,29.764 107.389,57.389C107.389,85.013 85.013,107.389 57.389,107.389C29.764,107.389 7.389,85.013 7.389,57.389z', transform: 'rotate(45 57.388671875000036,57.388671874999986) ', 'stroke-width': '5', diff --git a/cypress/integration/unit/test1.js b/cypress/integration/unit/test1.js index 07a2ab6f..5660d1a4 100644 --- a/cypress/integration/unit/test1.js +++ b/cypress/integration/unit/test1.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ import '../../../instrumented/editor/jquery.min.js'; import '../../../instrumented/editor/jquery-ui/jquery-ui-1.8.17.custom.min.js'; diff --git a/cypress/integration/unit/utilities-bbox.js b/cypress/integration/unit/utilities-bbox.js index c2be9af9..fb089803 100644 --- a/cypress/integration/unit/utilities-bbox.js +++ b/cypress/integration/unit/utilities-bbox.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ import '../../../instrumented/editor/jquery.min.js'; import '../../../instrumented/common/svgpathseg.js'; diff --git a/cypress/integration/unit/utilities-performance.js b/cypress/integration/unit/utilities-performance.js index 41d304d8..5a167b5a 100644 --- a/cypress/integration/unit/utilities-performance.js +++ b/cypress/integration/unit/utilities-performance.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ import '../../../instrumented/editor/jquery.min.js'; import '../../../instrumented/common/svgpathseg.js'; diff --git a/cypress/integration/unit/utilities.js b/cypress/integration/unit/utilities.js index 8bc8e3ca..e56bd63d 100644 --- a/cypress/integration/unit/utilities.js +++ b/cypress/integration/unit/utilities.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ import '../../../instrumented/editor/jquery.min.js'; import * as browser from '../../../instrumented/common/browser.js'; diff --git a/cypress/plugins/main.js b/cypress/plugins/main.js index 29c585f5..118423bf 100644 --- a/cypress/plugins/main.js +++ b/cypress/plugins/main.js @@ -3,7 +3,6 @@ import codeCoverageTask from '@cypress/code-coverage/task.js'; -// eslint-disable-next-line import/no-anonymous-default-export export default (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config diff --git a/cypress/support/assert-close.js b/cypress/support/assert-close.js index f5947f2d..7b79341b 100644 --- a/cypress/support/assert-close.js +++ b/cypress/support/assert-close.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ import assertionWrapper from './assertion-wrapper.js'; /** diff --git a/docs/jsdoc-config.js b/docs/jsdoc-config.js index 2bef4b19..e833febe 100644 --- a/docs/jsdoc-config.js +++ b/docs/jsdoc-config.js @@ -65,6 +65,7 @@ module.exports = { 'screencasts', 'test' ], + // eslint-disable-next-line max-len excludePattern: 'svgedit-config-*|build-html.js|rollup*|external/babel-polyfill|extensions/mathjax|imagelib/jquery.min.js|jspdf/jspdf.min.js|jspdf/underscore-min.js|jquery-ui|jquery.min.js|js-hotkeys' }, sourceType: 'module', diff --git a/package.json b/package.json index ea9ce13d..d083969b 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "remark": "remark -q -f .", "build-html": "babel-node --plugins @babel/plugin-transform-modules-commonjs build/build-html.js", "eslint-fix": "eslint --fix --ext js,md,html src", - "eslint": "eslint --ext js,html src", + "eslint": "eslint --ext js,html,md .", "rollup": "rollup -c", "build-by-config": "rollup -c rollup-config.config.js", "prep-no-core-rollup": "run-s eslint build-html build-by-config", diff --git a/rollup-config.config.js b/rollup-config.config.js index cb9d9ff9..236a94e4 100644 --- a/rollup-config.config.js +++ b/rollup-config.config.js @@ -34,7 +34,6 @@ window.svgEditor.modules = false; }) ]; -/* eslint-disable import/no-anonymous-default-export */ export default [ { input: 'svgedit-config-es.js', @@ -53,4 +52,3 @@ export default [ plugins } ]; -/* eslint-enable import/no-anonymous-default-export */ diff --git a/src/editor/svgicons/jQuery.svgIcons.js b/src/editor/svgicons/jQuery.svgIcons.js index ffba43fa..0f203771 100644 --- a/src/editor/svgicons/jQuery.svgIcons.js +++ b/src/editor/svgicons/jQuery.svgIcons.js @@ -49,7 +49,7 @@ This will return the icon (as jQuery object) with a given ID. // events for each icon $.each(icons, function (id, icon) { icon.click(function () { - alert('You clicked on the icon with id ' + id); // eslint-disable-line no-alert + alert('You clicked on the icon with id ' + id); }); }); }