diff --git a/.eslintrc.js b/.eslintrc.js index 6c5d636..1e53174 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,7 @@ module.exports = { extends: [ - "./lib/config/script.js", + "./lib/config/commonjs.js", "./lib/config/node.js", "./lib/config/esnext.js", "./lib/config/jsdoc-typescript.js", diff --git a/CHANGELOG.md b/CHANGELOG.md index 0511689..fb87230 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ rule (it is breaking changed by default). ## 134.0.0 - 2021-09-17 -- Changed: minimum required `eslint` version is `^7.32.0` +- Added: `commonjs` preset (before it was the `script` preset). +- Changed: `script` preset is now just `script`. +- Changed: minimum required `eslint` version is `^7.32.0`. - Changed: minimum required `eslint-plugin-import` version is now `2.24.2`. - Changed: minimum required `eslint-plugin-markdown` version is now `2.2.1`. - Changed: minimum required `eslint-plugin-jest` version is now `24.4.2`. diff --git a/README.md b/README.md index 6ae4d86..7f2b789 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,17 @@ module.exports = { This plugin provides the following core configurations: -- [script](lib/config/script.js): preset for [CommonJS modules](https://nodejs.org/docs/latest/api/modules.html) (`require`/`module.exports`/etc). +- [script](lib/config/script.js): preset for environment without `require`/`import` (old browsers or custom env). + +Example of configuration: + +```json +{ + "extends": ["plugin:itgalaxy/script"] +} +``` + +- [commonjs](lib/config/commonjs.js): preset for [CommonJS modules](https://nodejs.org/docs/latest/api/modules.html) (`require`/`module.exports`/etc). Example of configuration: @@ -129,7 +139,7 @@ console.log(import.meta.url); loadConfig("example"); ``` -- [node](lib/config/node.js): use this for `Node.js` projects. +- [node](lib/config/node.js): use this for `Node.js` projects (preset contains only environments rules, i.e. no rules for `require`/`import`, see above presets). Preset contains environment and rules for `Node.js` code. @@ -138,9 +148,9 @@ Example of configuration: ```js module.exports = { extends: [ - // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty" - "plugin:itgalaxy/module", "plugin:itgalaxy/esnext", + // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" + "plugin:itgalaxy/module", "plugin:itgalaxy/node", ], }; @@ -155,9 +165,9 @@ Example of configuration: ```js module.exports = { extends: [ - // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty" - "plugin:itgalaxy/module", "plugin:itgalaxy/esnext", + // You can use "plugin:itgalaxy/script" for old browsers or custom enviroment, "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers) + "plugin:itgalaxy/module", "plugin:itgalaxy/browser", ], }; @@ -174,9 +184,9 @@ Example of configuration: ```js module.exports = { extends: [ - // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty" - "plugin:itgalaxy/module", "plugin:itgalaxy/esnext", + // You can use "plugin:itgalaxy/script" for old browsers or custom enviroment, "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers) + "plugin:itgalaxy/module", ], }; ``` @@ -188,10 +198,10 @@ Example of configuration: ```js module.exports = { extends: [ - // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty" + "plugin:itgalaxy/esnext", + // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers) "plugin:itgalaxy/module", "plugin:itgalaxy/browser", - "plugin:itgalaxy/esnext", "plugin:itgalaxy/react", ], }; @@ -204,10 +214,10 @@ Example of configuration: ```js module.exports = { extends: [ - // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty" + "plugin:itgalaxy/esnext", + // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers) "plugin:itgalaxy/module", "plugin:itgalaxy/browser", - "plugin:itgalaxy/esnext", "plugin:itgalaxy/html", ], }; @@ -223,11 +233,10 @@ Example of configuration: ```js module.exports = { extends: [ - // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty" + "plugin:itgalaxy/esnext", + // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers) "plugin:itgalaxy/module", - // You can use "plugin:itgalaxy/node" or use them both "plugin:itgalaxy/browser", - "plugin:itgalaxy/esnext", "plugin:itgalaxy/markdown", ], }; @@ -240,10 +249,10 @@ Example of configuration: ```js module.exports = { extends: [ + "plugin:itgalaxy/esnext", + // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers) "plugin:itgalaxy/module", - // You can use "plugin:itgalaxy/node" or use them both "plugin:itgalaxy/browser", - "plugin:itgalaxy/esnext", "plugin:itgalaxy/ava", ], }; @@ -258,10 +267,10 @@ Example of configuration: ```js module.exports = { extends: [ + "plugin:itgalaxy/esnext", + // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers) "plugin:itgalaxy/module", - // You can use "plugin:itgalaxy/node" or use them both "plugin:itgalaxy/browser", - "plugin:itgalaxy/esnext", "plugin:itgalaxy/jest", ], }; @@ -274,9 +283,10 @@ Example of configuration: ```js module.exports = { extends: [ + "plugin:itgalaxy/esnext", + // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers) "plugin:itgalaxy/module", "plugin:itgalaxy/node", - "plugin:itgalaxy/esnext", "plugin:itgalaxy/jsdoc-typescript", ], }; @@ -293,10 +303,10 @@ module.exports = { module.exports = { extends: [ - "plugin:itgalaxy/script", - // Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments - "plugin:itgalaxy/node", "plugin:itgalaxy/esnext", + "plugin:itgalaxy/commonjs", + // Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments (you need bundler) + "plugin:itgalaxy/node", "plugin:itgalaxy/jest", // Lint documentation "plugin:itgalaxy/markdown", @@ -314,11 +324,11 @@ module.exports = { ```js export default { extends: [ - // You can change this on "plugin:itgalaxy/dirty" if you use `node-babel` and have mixed code with `import` and `require` + "plugin:itgalaxy/esnext", + // You can change this on "plugin:itgalaxy/dirty" if you use `node-babel`, bundler and have mixed code with `import` and `require` "plugin:itgalaxy/module", - // Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments + // Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments (you need bundler) "plugin:itgalaxy/node", - "plugin:itgalaxy/esnext", "plugin:itgalaxy/jest", // Lint documentation "plugin:itgalaxy/markdown", @@ -339,9 +349,9 @@ module.exports = { // if you use ECMA modules everywhere (preferable) // Configuration files and scripts extends: [ - "plugin:itgalaxy/script", "plugin:itgalaxy/esnext", - "plugin:itgalaxy/ava", + "plugin:itgalaxy/commonjs", + "plugin:itgalaxy/jest", // Lint documentation "plugin:itgalaxy/markdown", // Uncomment to use jsdoc typescript @@ -350,6 +360,7 @@ module.exports = { overrides: [ // Source code of application { + files: ["src/**/*.[jt]s?(x)"], extends: [ "plugin:itgalaxy/module", "plugin:itgalaxy/browser", @@ -359,7 +370,6 @@ module.exports = { // Do you use `jquery`? // jquery: true }, - files: ["src/**/*.[jt]s?(x)"], }, // Tests and documentation { @@ -375,9 +385,6 @@ module.exports = { "plugin:itgalaxy/browser", "plugin:itgalaxy/react", ], - rules: { - "import/no-nodejs-modules": "off", - }, }, ], root: true, diff --git a/__tests__/fixtures/commonjs.js b/__tests__/fixtures/commonjs.js new file mode 100644 index 0000000..3544b65 --- /dev/null +++ b/__tests__/fixtures/commonjs.js @@ -0,0 +1,11 @@ +const subScript = require("./sub-module"); + +function outputSomething(line) { + return line; +} + +outputSomething(subScript); +outputSomething(__filename); +outputSomething(__dirname); + +module.exports = outputSomething; diff --git a/__tests__/fixtures/script.js b/__tests__/fixtures/script.js index 3544b65..f36e5a0 100644 --- a/__tests__/fixtures/script.js +++ b/__tests__/fixtures/script.js @@ -1,11 +1,4 @@ -const subScript = require("./sub-module"); - function outputSomething(line) { return line; } - -outputSomething(subScript); -outputSomething(__filename); -outputSomething(__dirname); - -module.exports = outputSomething; +outputSomething("text"); diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 938d220..db9129d 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -71,8 +71,6 @@ test("should load the 'script' preset", (t) => { requireConfigFile: false, sourceType: "script", }); - t.true(configForFile.plugins.includes("import")); - t.true(configForFile.plugins.includes("node")); const scriptReport = cli.executeOnFiles([ path.resolve(__dirname, "./fixtures/script.js"), @@ -82,6 +80,60 @@ test("should load the 'script' preset", (t) => { t.is(scriptReport.errorCount, 0); t.is(scriptReport.warningCount, 0); + const commonjsReport = cli.executeOnFiles([ + path.resolve(__dirname, "./fixtures/commonjs.js"), + ]); + + t.is(commonjsReport.results.length, 1); + t.is(commonjsReport.errorCount, 4); + t.is(commonjsReport.warningCount, 0); + + const moduleReport = cli.executeOnFiles([ + path.resolve(__dirname, "./fixtures/module.js"), + ]); + + t.is(moduleReport.results.length, 1); + t.is(moduleReport.errorCount, 1); + t.is(moduleReport.warningCount, 0); + + t.true( + moduleReport.results[0].messages[0].message.includes( + "Parsing error: 'import' and 'export' may appear only with 'sourceType: \"module\"'" + ) + ); +}); + +test("should load the 'commonjs' preset", (t) => { + const cli = new eslint.CLIEngine({ + ignore: false, + useEslintrc: false, + baseConfig: { extends: ["./lib/config/commonjs.js"] }, + rules: { + "no-undef": "error", + }, + }); + + const configForFile = cli.getConfigForFile("myfile.js"); + + t.is(configForFile.parser, require.resolve("@babel/eslint-parser")); + t.deepEqual(configForFile.parserOptions, { + ecmaFeatures: { + globalReturn: true, + }, + requireConfigFile: false, + sourceType: "script", + }); + t.true(configForFile.plugins.includes("import")); + t.true(configForFile.plugins.includes("node")); + + const commonjsReport = cli.executeOnFiles([ + path.resolve(__dirname, "./fixtures/commonjs.js"), + ]); + + t.is(commonjsReport.results.length, 1); + t.is(commonjsReport.errorCount, 0); + t.is(commonjsReport.warningCount, 0); + const moduleReport = cli.executeOnFiles([ path.resolve(__dirname, "./fixtures/module.js"), ]); @@ -124,13 +176,13 @@ test("should load the 'module' preset", (t) => { sourceType: "module", }); - const scriptReport = cli.executeOnFiles([ - path.resolve(__dirname, "./fixtures/script.js"), + const commonjsReport = cli.executeOnFiles([ + path.resolve(__dirname, "./fixtures/commonjs.js"), ]); - t.is(scriptReport.results.length, 1); - t.is(scriptReport.errorCount, 5); - t.is(scriptReport.warningCount, 0); + t.is(commonjsReport.results.length, 1); + t.is(commonjsReport.errorCount, 5); + t.is(commonjsReport.warningCount, 0); const moduleReport = cli.executeOnFiles([ path.resolve(__dirname, "./fixtures/module.js"), @@ -188,6 +240,14 @@ test("should load the 'dirty' preset", (t) => { t.is(scriptReport.errorCount, 0); t.is(scriptReport.warningCount, 0); + const commonjsReport = cli.executeOnFiles([ + path.resolve(__dirname, "./fixtures/commonjs.js"), + ]); + + t.is(commonjsReport.results.length, 1); + t.is(commonjsReport.errorCount, 0); + t.is(commonjsReport.warningCount, 0); + const moduleReport = cli.executeOnFiles([ path.resolve(__dirname, "./fixtures/module.js"), ]); @@ -240,9 +300,9 @@ test("should load the 'esnext' preset", (t) => { useEslintrc: false, baseConfig: { extends: [ + "./lib/config/esnext.js", "./lib/config/module.js", "./lib/config/browser.js", - "./lib/config/esnext.js", ], }, rules: { @@ -288,8 +348,8 @@ test("should load the 'node' preset", (t) => { useEslintrc: false, baseConfig: { extends: [ - "./lib/config/script.js", "./lib/config/esnext.js", + "./lib/config/commonjs.js", "./lib/config/node.js", ], }, @@ -363,8 +423,8 @@ test("should load 'node' and 'browser' presets", (t) => { useEslintrc: false, baseConfig: { extends: [ - "./lib/config/script.js", "./lib/config/esnext.js", + "./lib/config/commonjs.js", "./lib/config/node.js", "./lib/config/browser.js", ], @@ -418,8 +478,8 @@ test("should load 'node' and 'browser' presets", (t) => { useEslintrc: false, baseConfig: { extends: [ - "./lib/config/script.js", "./lib/config/esnext.js", + "./lib/config/commonjs.js", "./lib/config/browser.js", "./lib/config/node.js", ], @@ -472,10 +532,10 @@ test("should load 'node' and 'browser' presets", (t) => { useEslintrc: false, baseConfig: { extends: [ - "./lib/config/script.js", + "./lib/config/esnext.js", + "./lib/config/commonjs.js", "./lib/config/browser.js", "./lib/config/node.js", - "./lib/config/esnext.js", ], }, rules: { diff --git a/index.js b/index.js index 87a4b8c..0cc200a 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,9 @@ const allConfig = require("./lib/config/all"); -const moduleConfig = require("./lib/config/module"); const scriptConfig = require("./lib/config/script"); +const moduleConfig = require("./lib/config/module"); +const commonjsConfig = require("./lib/config/commonjs"); const dirtyConfig = require("./lib/config/dirty"); const nodeConfig = require("./lib/config/node"); @@ -24,8 +25,9 @@ const markdownConfig = require("./lib/config/markdown"); const configs = { all: allConfig, - module: moduleConfig, script: scriptConfig, + module: moduleConfig, + commonjs: commonjsConfig, dirty: dirtyConfig, node: nodeConfig, diff --git a/lib/config/browser.js b/lib/config/browser.js index 68f283c..0ccc364 100644 --- a/lib/config/browser.js +++ b/lib/config/browser.js @@ -2,10 +2,8 @@ module.exports = { env: { browser: true }, - plugins: ["import", "unicorn"], + plugins: ["unicorn"], rules: { - "import/no-nodejs-modules": "error", - "unicorn/no-document-cookie": "error", "unicorn/prefer-add-event-listener": "error", "unicorn/prefer-dom-node-append": "error", diff --git a/lib/config/commonjs.js b/lib/config/commonjs.js new file mode 100644 index 0000000..07768ea --- /dev/null +++ b/lib/config/commonjs.js @@ -0,0 +1,12 @@ +"use strict"; + +const baseSharedConfig = require("./shared/base"); +const commonjsSharedConfig = require("./shared/commonjs"); + +module.exports = { + ...baseSharedConfig, + overrides: [ + ...baseSharedConfig.overrides, + { files: ["*.js", ".*.js"], ...commonjsSharedConfig }, + ], +}; diff --git a/lib/config/rules/import.js b/lib/config/rules/import.js index 91bf08d..084da86 100644 --- a/lib/config/rules/import.js +++ b/lib/config/rules/import.js @@ -74,7 +74,7 @@ module.exports = { // Report AMD require and define calls. "import/no-amd": "error", // No Node.js builtin modules. - // "import/no-nodejs-modules": "off", + "import/no-nodejs-modules": "off", // TODO test it // Forbid imports with CommonJS exports "import/no-import-module-exports": "off", @@ -123,5 +123,5 @@ module.exports = { // Need enable in next version "import/group-exports": "off", // Enforce a leading comment with the webpackChunkName for dynamic imports - "import/dynamic-import-chunkname": "error", + "import/dynamic-import-chunkname": "off", }; diff --git a/lib/config/rules/node.js b/lib/config/rules/node.js index ca177e7..4d4c092 100644 --- a/lib/config/rules/node.js +++ b/lib/config/rules/node.js @@ -6,32 +6,41 @@ module.exports = { // Disallow use of the Buffer() constructor // Disable rule in favor `node/no-deprecated-api`. "no-buffer-constructor": "off", - // Disallow process.exit() // Disallow certain properties on certain objects "no-restricted-properties": "off", + // Possible Errors + // Enforces error handling in callbacks + "node/handle-callback-err": ["error", "^.*(e|E)rr(or)?$"], // Ensures the Node.js error-first callback pattern is followed "node/no-callback-literal": "off", // Disallow the assignment to `exports` - "node/no-exports-assign": "error", + // "node/no-exports-assign": "off", // Disallow import declarations of extraneous packages // Use `import/no-extraneous-dependencies` rule - "node/no-extraneous-import": "off", + // "node/no-extraneous-import": "off", // Disallow require() expressions of extraneous packages // Use `import/no-extraneous-dependencies` rule - "node/no-extraneous-require": "off", + // "node/no-extraneous-require": "off", // Disallow import and export declarations for files that don't exist. // Use `import/no-unresolved` rule - "node/no-missing-import": "off", + // "node/no-missing-import": "off", // Disallow require()s for files that don't exist. // Use `import/no-unresolved` rule - "node/no-missing-require": "off", + // "node/no-missing-require": "off", + // Disallow use of new operator with the require function + // "node/no-new-require": "off", + // Disallow string concatenation with __dirname and __filename + "node/no-path-concat": "error", + // Disallow the use of process.exit() + // Prefer to use `unicorn/no-process-exit` + "node/no-process-exit": "off", // Disallow bin files that npm ignores. "node/no-unpublished-bin": "error", // Disallow import and export declarations for files that are not published. - "node/no-unpublished-import": "error", + // "node/no-unpublished-import": "off", // Disallow require()s for files that are not published. - "node/no-unpublished-require": "error", + // "node/no-unpublished-require": "off", // Disallow unsupported ECMAScript built-ins on the specified version "node/no-unsupported-features/es-builtins": "error", // Disallow unsupported ECMAScript syntax on the specified version @@ -49,16 +58,29 @@ module.exports = { // Stylistic Issues // Enforce either module.exports or exports. - "node/exports-style": [ + // Enforce return after a callback + "node/callback-return": [ "error", - "module.exports", - { - allowBatchAssign: false, - }, + ["callback", "cb", "done", "resolve", "reject"], ], + // Enforce either module.exports or exports. + // "node/exports-style": "off", // Enforce the style of file extensions in import declarations // Disable in favor `import/extensions` - "node/file-extension-in-import": "off", + // "node/file-extension-in-import": "off", + // Disallow require() outside of the top-level module scope + // Useful for optimizations + // "node/global-require": "off", + // Disallow require calls to be mixed with regular var declarations + // "node/no-mixed-requires": "off", + // Disallow process.env + "node/no-process-env": "off", + // Disallow specified modules when loaded by require, + // "node/no-restricted-import": "off", + // Restrict usage of specified node modules + // "node/no-restricted-require": "off", + // Disallow use of synchronous methods, + "node/no-sync": "error", // Enforce either `Buffer` or `require("buffer").Buffer` "node/prefer-global/buffer": ["error", "always"], // Enforce either `console` or `require("console")` @@ -66,46 +88,17 @@ module.exports = { // Enforce either `process` or `require("process")` "node/prefer-global/process": ["error", "always"], // Enforce either `TextDecoder` or `require("util").TextDecoder` - "node/prefer-global/text-decoder": "off", + "node/prefer-global/text-decoder": ["error", "always"], // Enforce either `TextEncoder` or `require("util").TextEncoder` - "node/prefer-global/text-encoder": "off", - // Enable after migrate on node@10 + "node/prefer-global/text-encoder": ["error", "always"], // Enforce either `URLSearchParams` or `require("url").URLSearchParams` - "node/prefer-global/url-search-params": "off", - // Enable after migrate on node@10 + "node/prefer-global/url-search-params": ["error", "always"], // enforce either `URL` or `require("url").URL` - "node/prefer-global/url": "off", - // Enable after migrate on node@10 + "node/prefer-global/url": ["error", "always"], + // No need // Enforce require("dns").promises "node/prefer-promises/dns": "off", - // Enable after migrate on node@10 + // No need // Enforce require("fs").promises "node/prefer-promises/fs": "off", - // Enforce return after a callback - "node/callback-return": [ - "error", - ["callback", "cb", "done", "resolve", "reject"], - ], - // Disallow require() outside of the top-level module scope - // Useful for optimizations - "node/global-require": "off", - // Enforces error handling in callbacks - "node/handle-callback-err": ["error", "^.*(e|E)rr(or)?$"], - // Disallow use of new operator with the require function - // "node/no-new-require": "off", - // Disallow require calls to be mixed with regular var declarations - // "node/no-mixed-requires": "off", - // Disallow string concatenation with __dirname and __filename - "node/no-path-concat": "error", - // Disallow process.env - "node/no-process-env": "off", - // Disallow the use of process.exit() - // Prefer to use `unicorn/no-process-exit` - "node/no-process-exit": "off", - // Restrict usage of specified node modules - "node/no-restricted-require": "off", - // Disallow use of synchronous methods, - "node/no-sync": "error", - // Disallow specified modules when loaded by require, - "node/no-restricted-import": "off", }; diff --git a/lib/config/shared/base.js b/lib/config/shared/base.js index 4ed6216..bf27a22 100644 --- a/lib/config/shared/base.js +++ b/lib/config/shared/base.js @@ -1,7 +1,7 @@ "use strict"; const parserSharedConfig = require("./parser"); -const scriptSharedConfig = require("./script"); +const commonjsSharedConfig = require("./commonjs"); const moduleSharedConfig = require("./module"); module.exports = { @@ -16,7 +16,7 @@ module.exports = { "**/__snapshots__/**", ], overrides: [ - { files: ["*.cjs", ".*.cjs"], ...scriptSharedConfig }, + { files: ["*.cjs", ".*.cjs"], ...commonjsSharedConfig }, { files: ["*.mjs", ".*.mjs"], ...moduleSharedConfig }, ], }; diff --git a/lib/config/shared/commonjs.js b/lib/config/shared/commonjs.js new file mode 100644 index 0000000..442dc2d --- /dev/null +++ b/lib/config/shared/commonjs.js @@ -0,0 +1,80 @@ +"use strict"; + +const parserSharedConfig = require("./parser"); +const importRules = require("../rules/import"); + +const scriptSharedConfig = { + parserOptions: { + ...parserSharedConfig.parserOptions, + sourceType: "script", + ecmaFeatures: { globalReturn: true }, + }, + globals: { + __dirname: "readonly", + __filename: "readonly", + exports: "writable", + module: "readonly", + require: "readonly", + }, + settings: { + "import/extensions": [".mjs", ".cjs", ".js"], + "import/ignore": ["\\.(coffee|scss|css|less|hbs|svg|json|md)$"], + "import/resolver": { + node: { extensions: [".mjs", ".cjs", ".js", ".jsx", ".json", ".node"] }, + }, + }, + plugins: ["import", "node"], + rules: { + ...importRules, + "import/extensions": [ + "error", + "always", + { + ignorePackages: true, + pattern: { + mjs: "never", + js: "never", + jsx: "never", + }, + }, + ], + "import/no-useless-path-segments": [ + "error", + { + commonjs: true, + noUselessIndex: true, + }, + ], + + // Possible Errors + "node/no-exports-assign": "error", + "node/no-extraneous-require": "off", + "node/no-missing-require": "off", + "node/no-new-require": "error", + "node/no-unpublished-require": "error", + "node/no-unsupported-features/es-syntax": [ + "error", + { ignores: ["dynamicImport"] }, + ], + + // Stylistic Issues + "node/exports-style": [ + "error", + "module.exports", + { + allowBatchAssign: false, + }, + ], + "node/global-require": "off", + "node/no-mixed-requires": [ + "error", + { + grouping: true, + allowCall: true, + }, + ], + "node/no-restricted-require": "off", + }, +}; + +module.exports = scriptSharedConfig; diff --git a/lib/config/shared/dirty.js b/lib/config/shared/dirty.js index 1c23e74..6a33367 100644 --- a/lib/config/shared/dirty.js +++ b/lib/config/shared/dirty.js @@ -28,10 +28,30 @@ const dirtySharedConfig = { ...importRules, "import/extensions": "off", + // Possible Errors + "node/no-exports-assign": "error", + "node/no-extraneous-require": "off", + "node/no-extraneous-import": "off", + "node/no-missing-require": "off", + "node/no-missing-import": "off", + "node/no-new-require": "error", + "node/no-unpublished-require": "error", + "node/no-unpublished-import": "error", "node/no-unsupported-features/es-syntax": [ "error", - { ignores: ["modules"] }, + { ignores: ["modules", "dynamicImport"] }, + ], + + // Stylistic Issues + "node/exports-style": [ + "error", + "module.exports", + { + allowBatchAssign: false, + }, ], + "node/file-extension-in-import": "off", + "node/global-require": "off", "node/no-mixed-requires": [ "error", { @@ -39,7 +59,9 @@ const dirtySharedConfig = { allowCall: true, }, ], - "node/no-new-require": "error", + "node/no-restricted-import": "off", + "node/no-restricted-require": "off", + "no-import-assign": "error", }, }; diff --git a/lib/config/shared/module.js b/lib/config/shared/module.js index 6778290..a481edf 100644 --- a/lib/config/shared/module.js +++ b/lib/config/shared/module.js @@ -47,11 +47,19 @@ const moduleSharedConfig = { }, ], + // Possible Errors + "node/no-extraneous-import": "off", + "node/no-missing-import": "off", + "node/no-unpublished-import": "error", "node/no-unsupported-features/es-syntax": [ "error", - { ignores: ["modules"] }, + { ignores: ["modules", "dynamicImport"] }, ], + // Stylistic Issues + "node/file-extension-in-import": "off", + "node/no-restricted-import": "off", + "no-import-assign": "error", }, }; diff --git a/lib/config/shared/script.js b/lib/config/shared/script.js index 1ecbbc4..9b9aeec 100644 --- a/lib/config/shared/script.js +++ b/lib/config/shared/script.js @@ -1,7 +1,6 @@ "use strict"; const parserSharedConfig = require("./parser"); -const importRules = require("../rules/import"); const scriptSharedConfig = { parserOptions: { @@ -9,53 +8,6 @@ const scriptSharedConfig = { sourceType: "script", ecmaFeatures: { globalReturn: true }, }, - globals: { - __dirname: "readonly", - __filename: "readonly", - exports: "writable", - module: "readonly", - require: "readonly", - }, - settings: { - "import/extensions": [".mjs", ".cjs", ".js"], - "import/ignore": ["\\.(coffee|scss|css|less|hbs|svg|json|md)$"], - "import/resolver": { - node: { extensions: [".mjs", ".cjs", ".js", ".jsx", ".json", ".node"] }, - }, - }, - plugins: ["import", "node"], - rules: { - ...importRules, - "node/no-unsupported-features/es-syntax": "error", - "import/extensions": [ - "error", - "always", - { - ignorePackages: true, - pattern: { - mjs: "never", - js: "never", - jsx: "never", - }, - }, - ], - "import/no-useless-path-segments": [ - "error", - { - commonjs: true, - noUselessIndex: true, - }, - ], - - "node/no-mixed-requires": [ - "error", - { - grouping: true, - allowCall: true, - }, - ], - "node/no-new-require": "error", - }, }; module.exports = scriptSharedConfig;