svgedit/.eslintrc.js

280 lines
7.7 KiB
JavaScript
Raw Normal View History

2021-02-23 22:39:14 +00:00
"use strict";
- Breaking change: `loadSvgString` now returns a `Promise` rather than accepting a callback - Breaking change: Treat callbacks to `editor.ready` as Promises, only resolving after all resolve - Breaking change: Make `editor.runCallbacks` return a `Promise` which resolves upon all callbacks resolving - Breaking change: Require `npx` (used with `babel-node`) to allow Node files for HTML building and JSDoc type checking to be expressed as ESM. - Breaking change: `addExtension` now throws upon a repeated attempt to add an already-added extension - Breaking change (storage preference cookies): Namespace the cookie as "svgeditstore" instead of just "store" - Breaking change (API): Remove `svgCanvas.rasterExport` fourth (callback) argument, collapsing fifth (options) to fourth - Breaking change (API): Remove `svgCanvas.exportPDF` third (callback) argument - Breaking change (API): `editor/contextmenu.js` `add` now throws instead of giving a console error only upon detecting a bad menuitem or preexisting context menu - Breaking change (API): Remove `svgCanvas.embedImage` second (callback) argument - Breaking change (API): Make `getHelpXML` a class instead of instance method of `RGBColor` - Breaking change (internal API): Refactor `dbox` (and `alert`/`confirm`/`process`/`prompt`/`select`) to avoid a callback argument in favor of return a Promise - Fix: Avoid running in extension `langReady` multiple times or serially - Enhancement (API): Add svgCanvas.runExtension to run just one extension and add `nameFilter` callback to `runExtensions` - Enhancement (API): Supply `$` (our wrapped jQuery) to extensions so can use its plugins, e.g., dbox with its `alert` - Enhancement: Use alert dialog in place of `alert` in webappfind - Enhancement: `editor.ready` now returns a Promise resolving when all callbacks have resolved - Enhancement: Allow `noAlert` option as part of second argument to `loadSvgString` (and `loadFromURL` and `loadFromDataURI`) to avoid UI alert (and trigger promise rejection) - Enhancement: Make `dbox` as a separate module for alert, prompt, etc. dialogs - Refactoring: Internal `PaintBox` as class; other misc. tweaks; no bitwise in canvg - Linting (ESLint): Further linting changes (for editor); rename `.eslintrc` -> `.eslintrc.json` per recommendation - Optimization: Recompress images (imageoptim-cli updated) - npm: Update devDeps - npm: Bump to 4.0.0
2018-11-08 06:48:01 +00:00
module.exports = {
2021-02-23 22:39:14 +00:00
extends: [
"plugin:compat/recommended",
"plugin:node/recommended",
"plugin:no-unsanitized/DOM",
"plugin:promise/recommended",
"plugin:import/errors",
"plugin:markdown/recommended",
"plugin:sonarjs/recommended"
],
plugins: ["jsdoc", "promise", "html", "import", "sonarjs"],
2018-11-16 07:15:17 +00:00
parserOptions: {
2020-07-31 23:23:28 +00:00
ecmaVersion: 2020,
2021-02-23 22:39:14 +00:00
sourceType: "module"
- Breaking change: `loadSvgString` now returns a `Promise` rather than accepting a callback - Breaking change: Treat callbacks to `editor.ready` as Promises, only resolving after all resolve - Breaking change: Make `editor.runCallbacks` return a `Promise` which resolves upon all callbacks resolving - Breaking change: Require `npx` (used with `babel-node`) to allow Node files for HTML building and JSDoc type checking to be expressed as ESM. - Breaking change: `addExtension` now throws upon a repeated attempt to add an already-added extension - Breaking change (storage preference cookies): Namespace the cookie as "svgeditstore" instead of just "store" - Breaking change (API): Remove `svgCanvas.rasterExport` fourth (callback) argument, collapsing fifth (options) to fourth - Breaking change (API): Remove `svgCanvas.exportPDF` third (callback) argument - Breaking change (API): `editor/contextmenu.js` `add` now throws instead of giving a console error only upon detecting a bad menuitem or preexisting context menu - Breaking change (API): Remove `svgCanvas.embedImage` second (callback) argument - Breaking change (API): Make `getHelpXML` a class instead of instance method of `RGBColor` - Breaking change (internal API): Refactor `dbox` (and `alert`/`confirm`/`process`/`prompt`/`select`) to avoid a callback argument in favor of return a Promise - Fix: Avoid running in extension `langReady` multiple times or serially - Enhancement (API): Add svgCanvas.runExtension to run just one extension and add `nameFilter` callback to `runExtensions` - Enhancement (API): Supply `$` (our wrapped jQuery) to extensions so can use its plugins, e.g., dbox with its `alert` - Enhancement: Use alert dialog in place of `alert` in webappfind - Enhancement: `editor.ready` now returns a Promise resolving when all callbacks have resolved - Enhancement: Allow `noAlert` option as part of second argument to `loadSvgString` (and `loadFromURL` and `loadFromDataURI`) to avoid UI alert (and trigger promise rejection) - Enhancement: Make `dbox` as a separate module for alert, prompt, etc. dialogs - Refactoring: Internal `PaintBox` as class; other misc. tweaks; no bitwise in canvg - Linting (ESLint): Further linting changes (for editor); rename `.eslintrc` -> `.eslintrc.json` per recommendation - Optimization: Recompress images (imageoptim-cli updated) - npm: Update devDeps - npm: Bump to 4.0.0
2018-11-08 06:48:01 +00:00
},
2018-11-16 07:15:17 +00:00
env: {
2020-07-26 18:11:18 +00:00
browser: true,
2021-02-23 22:39:14 +00:00
es6: true
- Breaking change: `loadSvgString` now returns a `Promise` rather than accepting a callback - Breaking change: Treat callbacks to `editor.ready` as Promises, only resolving after all resolve - Breaking change: Make `editor.runCallbacks` return a `Promise` which resolves upon all callbacks resolving - Breaking change: Require `npx` (used with `babel-node`) to allow Node files for HTML building and JSDoc type checking to be expressed as ESM. - Breaking change: `addExtension` now throws upon a repeated attempt to add an already-added extension - Breaking change (storage preference cookies): Namespace the cookie as "svgeditstore" instead of just "store" - Breaking change (API): Remove `svgCanvas.rasterExport` fourth (callback) argument, collapsing fifth (options) to fourth - Breaking change (API): Remove `svgCanvas.exportPDF` third (callback) argument - Breaking change (API): `editor/contextmenu.js` `add` now throws instead of giving a console error only upon detecting a bad menuitem or preexisting context menu - Breaking change (API): Remove `svgCanvas.embedImage` second (callback) argument - Breaking change (API): Make `getHelpXML` a class instead of instance method of `RGBColor` - Breaking change (internal API): Refactor `dbox` (and `alert`/`confirm`/`process`/`prompt`/`select`) to avoid a callback argument in favor of return a Promise - Fix: Avoid running in extension `langReady` multiple times or serially - Enhancement (API): Add svgCanvas.runExtension to run just one extension and add `nameFilter` callback to `runExtensions` - Enhancement (API): Supply `$` (our wrapped jQuery) to extensions so can use its plugins, e.g., dbox with its `alert` - Enhancement: Use alert dialog in place of `alert` in webappfind - Enhancement: `editor.ready` now returns a Promise resolving when all callbacks have resolved - Enhancement: Allow `noAlert` option as part of second argument to `loadSvgString` (and `loadFromURL` and `loadFromDataURI`) to avoid UI alert (and trigger promise rejection) - Enhancement: Make `dbox` as a separate module for alert, prompt, etc. dialogs - Refactoring: Internal `PaintBox` as class; other misc. tweaks; no bitwise in canvg - Linting (ESLint): Further linting changes (for editor); rename `.eslintrc` -> `.eslintrc.json` per recommendation - Optimization: Recompress images (imageoptim-cli updated) - npm: Update devDeps - npm: Bump to 4.0.0
2018-11-08 06:48:01 +00:00
},
settings: {
polyfills: [
// These are the primary polyfills needed by regular users if
// not present, e.g., with core-js-bundle; also those under
// extensions
2021-02-23 22:39:14 +00:00
"fetch",
"Promise",
"Promise.all",
// 'Set',
"Uint8Array",
"URL"
]
},
2018-11-16 07:15:17 +00:00
rules: {
// check-examples is not picking up eslint config properly in some
// environments; see also discussion above
// `mocha-cleanup/no-assertions-outside-it`
2021-02-23 22:39:14 +00:00
"sonarjs/cognitive-complexity": 0,
"sonarjs/no-duplicate-string": 0,
"sonarjs/no-collapsible-if": 0,
"sonarjs/no-small-switch": 0,
"sonarjs/no-identical-functions": 0,
"sonarjs/no-duplicated-branches": 0,
"jsdoc/check-examples": [
"warn",
{
rejectExampleCodeRegex: "^`",
checkDefaults: true,
checkParams: true,
checkProperties: true
}
],
// The Babel transform seems to have a problem converting these
2021-02-23 22:39:14 +00:00
"prefer-named-capture-group": "off",
"jsdoc/require-file-overview": [
"error",
{
tags: {
file: {
initialCommentsOnly: true,
preventDuplicates: true
},
license: {
initialCommentsOnly: true,
preventDuplicates: true
},
copyright: {
initialCommentsOnly: true,
preventDuplicates: true
},
author: {
initialCommentsOnly: true,
preventDuplicates: true
},
module: {
initialCommentsOnly: true,
preventDuplicates: true
},
exports: {
initialCommentsOnly: true,
preventDuplicates: true
}
}
}
],
2020-07-26 18:11:18 +00:00
// Warning or Off for now but should be reviewed
// Override these rules which are difficult for us
// to apply at this time
2021-02-23 22:39:14 +00:00
"default-case": "off",
"require-unicode-regexp": "off",
"max-len": ["warn", { ignoreComments: true, code: 130 }], // 130 is too much but too many occurences
"eslint-comments/require-description": "off",
"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/es-syntax": "off",
"no-unsanitized/method": [
"error",
{
escape: {
methods: ["encodeURIComponent", "encodeURI"]
}
}
]
2020-07-26 18:11:18 +00:00
},
overrides: [
// Locales have no need for importing outside of SVG-Edit
// and translations may need a longer line length
{
files: [
2021-02-23 22:39:14 +00:00
'src/editor/locale/lang.*.js',
'src/editor/extensions/*/locale/**',
'docs/tutorials/ExtensionDocs.md/*.js'
2020-07-26 18:11:18 +00:00
],
rules: {
2021-02-23 22:39:14 +00:00
"import/no-anonymous-default-export": "off",
"max-len": "off",
"node/no-missing-import": "off",
"import/no-unresolved": "off"
2020-07-26 18:11:18 +00:00
}
2020-07-31 23:23:28 +00:00
},
2021-02-23 22:39:14 +00:00
// These browser files don't do importing or requiring
2020-07-31 23:23:28 +00:00
{
2021-02-23 22:39:14 +00:00
files: [
"src/editor/touch.js",
"src/editor/typedefs.js",
"src/editor/redirect-on-no-module-support.js",
"src/editor/extensions/ext-imagelib/index.js",
"screencasts/svgopen2010/script.js"
],
rules: {
"import/unambiguous": ["off"]
}
2020-07-31 23:23:28 +00:00
},
{
2021-02-23 22:39:14 +00:00
files: ["**/*.html", "screencasts/**"],
globals: {
root: "off"
},
settings: {
polyfills: [
"document.querySelector",
"history",
"history.pushState",
"history.replaceState",
"location.hash",
"navigator",
"Number.parseFloat",
"Number.parseInt",
"Number.isNaN"
]
},
2020-07-31 23:23:28 +00:00
rules: {
2021-02-23 22:39:14 +00:00
"import/unambiguous": "off"
2020-07-31 23:23:28 +00:00
}
},
{
// As consumed by jsdoc, cannot be expressed as ESM
2021-02-23 22:39:14 +00:00
files: ["docs/jsdoc-config.js"],
2020-07-31 23:23:28 +00:00
parserOptions: {
2021-02-23 22:39:14 +00:00
sourceType: "script"
2020-07-31 23:23:28 +00:00
},
globals: {
module: false
},
rules: {
2021-02-23 22:39:14 +00:00
"import/no-commonjs": "off",
strict: "off"
2020-07-31 23:23:28 +00:00
}
},
{
2021-02-23 22:39:14 +00:00
files: ["cypress/**"],
2020-07-31 23:23:28 +00:00
extends: [
2021-02-23 22:39:14 +00:00
"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"
2020-07-31 23:23:28 +00:00
],
env: {
node: true
},
settings: {
polyfills: [
2021-02-23 22:39:14 +00:00
"console",
"Date.now",
"document.body",
"document.createElementNS",
"document.head",
"DOMParser",
"Number.isNaN",
"Object.keys",
"Object.entries",
"Promise"
2020-07-31 23:23:28 +00:00
]
},
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
2021-02-23 22:39:14 +00:00
"import/no-unresolved": ["error", { ignore: ["/instrumented/"] }],
"node/no-missing-import": "off",
"jsdoc/check-examples": "off",
"chai-expect-keywords/no-unsupported-keywords": [
"error",
{
2020-07-31 23:23:28 +00:00
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,
2021-02-23 22:39:14 +00:00
"cypress/assertion-before-screenshot": 2,
2020-07-31 23:23:28 +00:00
// Conflicts with Cypress `should`
2021-02-23 22:39:14 +00:00
"mocha-cleanup/invalid-assertions": 0,
2020-07-31 23:23:28 +00:00
// Might see about working around to avoid the option limitation,
// but convenient
2021-02-23 22:39:14 +00:00
"mocha-cleanup/no-expressions-in-assertions": [
"error",
{
replacementsOnly: true
}
],
2020-07-31 23:23:28 +00:00
// Too oppressive when planning to extend a section
2021-02-23 22:39:14 +00:00
"mocha/no-hooks-for-single-case": 0,
2020-07-31 23:23:28 +00:00
// Would be good to enable but needs some refactoring
2021-02-23 22:39:14 +00:00
"mocha/no-setup-in-describe": 0,
"mocha-cleanup/no-outside-declaration": 0,
2020-07-31 23:23:28 +00:00
// Useful to ensure allowing `this.timeout()`, etc., but a
// little oppressive
2021-02-23 22:39:14 +00:00
"mocha/no-mocha-arrows": 0,
2020-07-31 23:23:28 +00:00
// Useful if enabling the regular `prefer-arrow-callback`
// 'mocha/prefer-arrow-callback': 2
2021-02-23 22:39:14 +00:00
"jsdoc/require-jsdoc": 0,
"no-console": 0,
"import/unambiguous": 0
2020-07-31 23:23:28 +00:00
}
},
{
// Node files
files: [
2021-02-23 22:39:14 +00:00
"docs/jsdoc-config.js",
"build/build-html.js",
"rollup.config.js",
"rollup-config.config.js"
2020-07-31 23:23:28 +00:00
],
env: {
node: true
},
settings: {
2021-02-23 22:39:14 +00:00
polyfills: ["console", "Promise.resolve"]
2020-07-31 23:23:28 +00:00
},
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
2021-02-23 22:39:14 +00:00
"node/no-unpublished-import": "off"
2020-07-31 23:23:28 +00:00
}
2020-07-26 18:11:18 +00:00
}
]
2021-02-23 22:39:14 +00:00
};