From f2cad86b1cd66dafa0f2b54c796a70e93ccb97a0 Mon Sep 17 00:00:00 2001 From: Charlike Mike Reagent Date: Wed, 20 Jun 2018 21:50:53 +0300 Subject: [PATCH] fix(cjs): update to cjs, remove esm dep Signed-off-by: Charlike Mike Reagent --- package.json | 10 +- src/cli.js | 1 + src/index.js | 249 ++++++++++++++++++++++++++++++++++- src/index.mjs | 247 ---------------------------------- test/{index.mjs => index.js} | 2 +- 5 files changed, 251 insertions(+), 258 deletions(-) delete mode 100644 src/index.mjs rename test/{index.mjs => index.js} (67%) diff --git a/package.json b/package.json index e14942e..72500d4 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,9 @@ "version": "0.0.0-new-release-placeholder", "description": "Zero-config linting, powered by few amazing unicorns, AirBnB & Prettier.", "main": "src/", - "module": "src/index.mjs", "scripts": { "lint": "xaxa", - "test": "node -r esm test", + "test": "node test", "precommit": "yarn lint && yarn test && yarn gitadd", "gitadd": "git status --porcelain && git add -A", "precommit-dry": "yarn gitadd", @@ -29,19 +28,18 @@ "eslint-plugin-prettier": "^2.6.0", "eslint-plugin-react": "^7.8.2", "eslint-plugin-unicorn": "^4.0.3", - "esm": "^3.0.48", "mri": "^1.1.1", "prettier": "^1.12.1", "prettier-eslint": "^8.8.1" }, "devDependencies": { - "asia": "^0.3.3", + "asia": "*", "gitcommit": "^1.0.7", "new-release": "^4.0.1", - "xaxa": "^0.3.4" + "xaxa": "*" }, "eslintConfig": { - "extends": "./src/index.js" + "extends": "./node_modules/xaxa/src/index.js" }, "publishConfig": { "access": "public" diff --git a/src/cli.js b/src/cli.js index dc6d26f..0474cad 100755 --- a/src/cli.js +++ b/src/cli.js @@ -22,6 +22,7 @@ if (argv.require) { require(argv.require); } +// TODO: expose as API const cli = new CLIEngine({ useEslintrc: false, cache: true, diff --git a/src/index.js b/src/index.js index ff2c9cf..296ac86 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,247 @@ -const esmLoader = require('esm'); +module.exports = { + parser: 'babel-eslint', + extends: ['airbnb', 'prettier', 'prettier/flowtype', 'prettier/react'], + plugins: ['unicorn', 'flowtype', 'node', 'prettier'], + rules: { + // Enforce using named functions when regular function is used, + // otherwise use arrow functions + 'func-names': ['error', 'always'], -const esmRequire = esmLoader(module); -const m = esmRequire('./index.mjs'); + // Always use parens (for consistency). + // https://eslint.org/docs/rules/arrow-parens + 'arrow-parens': ['error', 'always', { requireForBlockBody: true }], -module.exports = typeof m === 'object' && 'default' in m ? m.default : m; + 'prefer-arrow-callback': [ + 'error', + { allowNamedFunctions: true, allowUnboundThis: true }, + ], + + // http://eslint.org/docs/rules/max-params + 'max-params': ['error', { max: 5 }], + + // http://eslint.org/docs/rules/max-statements + 'max-statements': ['error', { max: 20 }], + + // http://eslint.org/docs/rules/max-statements-per-line + 'max-statements-per-line': ['error', { max: 1 }], + + // http://eslint.org/docs/rules/max-nested-callbacks + 'max-nested-callbacks': ['error', { max: 5 }], + + // http://eslint.org/docs/rules/max-depth + 'max-depth': ['error', { max: 5 }], + + // enforces no braces where they can be omitted + // https://eslint.org/docs/rules/arrow-body-style + // Never enable for object literal. + 'arrow-body-style': [ + 'error', + 'as-needed', + { + requireReturnForObjectLiteral: false, + }, + ], + + // Allow functions to be use before define because: + // 1) they are hoisted, + // 2) because ensure read flow is from top to bottom + // 3) logically order of the code. + 'no-use-before-define': [ + 'error', + { + functions: false, + classes: true, + variables: true, + }, + ], + + // Same as AirBnB, but adds `opts`, `options` and `err` to exclusions + // disallow reassignment of function parameters + // disallow parameter object manipulation except for specific exclusions + // rule: https://eslint.org/docs/rules/no-param-reassign.html + 'no-param-reassign': [ + 'error', + { + props: true, + ignorePropertyModificationsFor: [ + 'acc', // for reduce accumulators + 'e', // for e.returnvalue + 'err', // for adding to the Error instance + 'ctx', // for Koa routing + 'req', // for Express requests + 'request', // for Express requests + 'res', // for Express responses + 'response', // for Express responses + '$scope', // for Angular 1 scopes + 'opts', // useful to ensure the params is always obect + 'options', // and when using Object.assign for shallow copy + ], + }, + ], + + 'prettier/prettier': [ + 'error', + { + // Explicitness is the most important thing: + // - Always is visible that this is function (because the parens). + // - If you first write single param and decide to add new one, + // then you should also add a parens around the both - that's mess. + arrowParens: 'always', + + // Always useful. And guaranteed that you won't see boring errors, + // that eats your time, because of nothing real. + trailingComma: 'all', + + // Enforce more clear object literals. + // That actually is enforced by AirBnB Style anyway. + // As seen in this example https://github.com/airbnb/javascript#objects--rest-spread + bracketSpacing: true, + + // Enforcing bracket on the next line makes differentiate + // where ends the tag and its properties and where starts the content of the tag. + // https://prettier.io/docs/en/options.html#jsx-brackets + jsxBracketSameLine: false, + + /** + * Configurable ones. + */ + + // Ensure Babylon parser is used for javascript. + // It is possible to change it through flag if you write in Flow or TypeScript. + parser: 'babylon', + + // Enforce single-quotes, because industry standard. + singleQuote: true, + + // Enforce 2 spaces, because JavaScript is always different + // then the rest of the languages. + tabWidth: 2, + }, + { + usePrettierrc: false, + }, + ], + + // TODO: update + 'import/extensions': 'off', + 'import/no-extraneous-dependencies': 'off', + 'import/no-unresolved': 'off', + + // Enforce throwing instead of `process.exit`. + // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/process-exit-as-throw.md + 'node/process-exit-as-throw': 'error', + + // Ensure we don't import something that is ignored. + // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/process-exit-as-throw.md + 'node/no-unpublished-import': 'off', + + // Ensure we have the defined bin file. + // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/process-exit-as-throw.md + 'node/no-unpublished-bin': 'error', + + // Don't use deprecated APIs + // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-deprecated-api.md + 'node/no-deprecated-api': 'error', + + // It is pretty common to name it `err`, + // and there is almost no reason to be any other. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/catch-error-name.md + 'unicorn/catch-error-name': ['error', { name: 'err' }], + + // Enforce explicitly comparing the length property of a value. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/explicit-length-check.md + 'unicorn/explicit-length-check': 'error', + + // Pretty useful rule, but it depends. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/filename-case.md + 'unicorn/filename-case': 'off', + + // Enforce specifying rules to disable in `eslint-disable` comments. + // Be explicit and don't just disable everything. If you want to disable + // everything because of more errors, reconsider your style or disable that rule temporary. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-abusive-eslint-disable.md + 'unicorn/no-abusive-eslint-disable': 'error', + + // Disallow `process.exit`, also related to `node/process-exit-as-throw` rule. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-process-exit.md + 'unicorn/no-process-exit': 'error', + + // Require new when throwing an error. (fixable) + // Don't throw strigs or some other weird things. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/throw-new-error.md + 'unicorn/throw-new-error': 'error', + + // Enforce lowercase identifier and uppercase value for number literals. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/number-literal-case.md + 'unicorn/number-literal-case': 'error', + + // Require escape sequences to use uppercase values. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/escape-case.md + 'unicorn/escape-case': 'error', + + // Require `Array.isArray()` instead of `instanceof Array`. (fixable) + // If you need such thing in rare cases, just disable that rule for that + // specific case and be explicit. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-array-instanceof.md + 'unicorn/no-array-instanceof': 'error', + + // Enforce the use of Buffer.from() and Buffer.alloc() instead of the deprecated ones. + // Also related to the `node/no-deprecated-api` rule. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-new-buffer.md + 'unicorn/no-new-buffer': 'error', + + // Enforce the use of unicode escapes instead of hexadecimal escapes. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-hex-escape.md + 'unicorn/no-hex-escape': 'error', + + // Enforce proper Error subclassing. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/custom-error-definition.md + 'unicorn/custom-error-definition': 'error', + + // Prefer `String#startsWith` & `String#endsWith` over more complex alternatives. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-starts-ends-with.md + 'unicorn/prefer-starts-ends-with': 'error', + + // Enforce throwing TypeError in type checking conditions. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-type-error.md + 'unicorn/prefer-type-error': 'error', + + // Prevents passing a function reference directly to iterator methods. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-fn-reference-in-iterator.md + 'unicorn/no-fn-reference-in-iterator': 'off', + + // Enforce importing index files with `.` instead of `./index`. (fixable) + // But we should be explicit. We know it is working without that, + // but at least it is good for newcomers. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/import-index.md + 'unicorn/import-index': 'off', + + // Enforce the use of new for all builtins, except String, Number and Boolean. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/new-for-builtins.md + 'unicorn/new-for-builtins': 'error', + + // Enforce the use of regex shorthands to improve readability. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/regex-shorthand.md + 'unicorn/regex-shorthand': 'error', + + // Prefer the spread operator over `Array.from()`. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-spread.md + 'unicorn/prefer-spread': 'error', + + // Enforce passing a message value when throwing a built-in error. + // "Be explicit" is our motto. Makes errors more useful. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/error-message.md + 'unicorn/error-message': 'error', + + // Disallow unsafe regular expressions. + // Don't allow potential catastrophic crashes, + // slow behaving and downtimes. You still can disable that + // and do whatever you want, but that will be explicit and visible. + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-unsafe-regex.md + 'unicorn/no-unsafe-regex': 'error', + + // Prefer `addEventListener` over `on`-functions in DOM APIs. (fixable) + // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-add-event-listener.md + 'unicorn/prefer-add-event-listener': 'error', + }, +}; diff --git a/src/index.mjs b/src/index.mjs deleted file mode 100644 index 47a4d26..0000000 --- a/src/index.mjs +++ /dev/null @@ -1,247 +0,0 @@ -export default { - parser: 'babel-eslint', - extends: ['airbnb', 'prettier', 'prettier/flowtype', 'prettier/react'], - plugins: ['unicorn', 'flowtype', 'node', 'prettier'], - rules: { - // Enforce using named functions when regular function is used, - // otherwise use arrow functions - 'func-names': ['error', 'always'], - - // Always use parens (for consistency). - // https://eslint.org/docs/rules/arrow-parens - 'arrow-parens': ['error', 'always', { requireForBlockBody: true }], - - 'prefer-arrow-callback': [ - 'error', - { allowNamedFunctions: true, allowUnboundThis: true }, - ], - - // http://eslint.org/docs/rules/max-params - 'max-params': ['error', { max: 5 }], - - // http://eslint.org/docs/rules/max-statements - 'max-statements': ['error', { max: 20 }], - - // http://eslint.org/docs/rules/max-statements-per-line - 'max-statements-per-line': ['error', { max: 1 }], - - // http://eslint.org/docs/rules/max-nested-callbacks - 'max-nested-callbacks': ['error', { max: 5 }], - - // http://eslint.org/docs/rules/max-depth - 'max-depth': ['error', { max: 5 }], - - // enforces no braces where they can be omitted - // https://eslint.org/docs/rules/arrow-body-style - // Never enable for object literal. - 'arrow-body-style': [ - 'error', - 'as-needed', - { - requireReturnForObjectLiteral: false, - }, - ], - - // Allow functions to be use before define because: - // 1) they are hoisted, - // 2) because ensure read flow is from top to bottom - // 3) logically order of the code. - 'no-use-before-define': [ - 'error', - { - functions: false, - classes: true, - variables: true, - }, - ], - - // Same as AirBnB, but adds `opts`, `options` and `err` to exclusions - // disallow reassignment of function parameters - // disallow parameter object manipulation except for specific exclusions - // rule: https://eslint.org/docs/rules/no-param-reassign.html - 'no-param-reassign': [ - 'error', - { - props: true, - ignorePropertyModificationsFor: [ - 'acc', // for reduce accumulators - 'e', // for e.returnvalue - 'err', // for adding to the Error instance - 'ctx', // for Koa routing - 'req', // for Express requests - 'request', // for Express requests - 'res', // for Express responses - 'response', // for Express responses - '$scope', // for Angular 1 scopes - 'opts', // useful to ensure the params is always obect - 'options', // and when using Object.assign for shallow copy - ], - }, - ], - - 'prettier/prettier': [ - 'error', - { - // Explicitness is the most important thing: - // - Always is visible that this is function (because the parens). - // - If you first write single param and decide to add new one, - // then you should also add a parens around the both - that's mess. - arrowParens: 'always', - - // Always useful. And guaranteed that you won't see boring errors, - // that eats your time, because of nothing real. - trailingComma: 'all', - - // Enforce more clear object literals. - // That actually is enforced by AirBnB Style anyway. - // As seen in this example https://github.com/airbnb/javascript#objects--rest-spread - bracketSpacing: true, - - // Enforcing bracket on the next line makes differentiate - // where ends the tag and its properties and where starts the content of the tag. - // https://prettier.io/docs/en/options.html#jsx-brackets - jsxBracketSameLine: false, - - /** - * Configurable ones. - */ - - // Ensure Babylon parser is used for javascript. - // It is possible to change it through flag if you write in Flow or TypeScript. - parser: 'babylon', - - // Enforce single-quotes, because industry standard. - singleQuote: true, - - // Enforce 2 spaces, because JavaScript is always different - // then the rest of the languages. - tabWidth: 2, - }, - { - usePrettierrc: false, - }, - ], - - // TODO: update - 'import/extensions': 'off', - 'import/no-extraneous-dependencies': 'off', - 'import/no-unresolved': 'off', - - // Enforce throwing instead of `process.exit`. - // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/process-exit-as-throw.md - 'node/process-exit-as-throw': 'error', - - // Ensure we don't import something that is ignored. - // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/process-exit-as-throw.md - 'node/no-unpublished-import': 'off', - - // Ensure we have the defined bin file. - // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/process-exit-as-throw.md - 'node/no-unpublished-bin': 'error', - - // Don't use deprecated APIs - // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-deprecated-api.md - 'node/no-deprecated-api': 'error', - - // It is pretty common to name it `err`, - // and there is almost no reason to be any other. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/catch-error-name.md - 'unicorn/catch-error-name': ['error', { name: 'err' }], - - // Enforce explicitly comparing the length property of a value. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/explicit-length-check.md - 'unicorn/explicit-length-check': 'error', - - // Pretty useful rule, but it depends. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/filename-case.md - 'unicorn/filename-case': 'off', - - // Enforce specifying rules to disable in `eslint-disable` comments. - // Be explicit and don't just disable everything. If you want to disable - // everything because of more errors, reconsider your style or disable that rule temporary. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-abusive-eslint-disable.md - 'unicorn/no-abusive-eslint-disable': 'error', - - // Disallow `process.exit`, also related to `node/process-exit-as-throw` rule. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-process-exit.md - 'unicorn/no-process-exit': 'error', - - // Require new when throwing an error. (fixable) - // Don't throw strigs or some other weird things. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/throw-new-error.md - 'unicorn/throw-new-error': 'error', - - // Enforce lowercase identifier and uppercase value for number literals. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/number-literal-case.md - 'unicorn/number-literal-case': 'error', - - // Require escape sequences to use uppercase values. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/escape-case.md - 'unicorn/escape-case': 'error', - - // Require `Array.isArray()` instead of `instanceof Array`. (fixable) - // If you need such thing in rare cases, just disable that rule for that - // specific case and be explicit. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-array-instanceof.md - 'unicorn/no-array-instanceof': 'error', - - // Enforce the use of Buffer.from() and Buffer.alloc() instead of the deprecated ones. - // Also related to the `node/no-deprecated-api` rule. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-new-buffer.md - 'unicorn/no-new-buffer': 'error', - - // Enforce the use of unicode escapes instead of hexadecimal escapes. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-hex-escape.md - 'unicorn/no-hex-escape': 'error', - - // Enforce proper Error subclassing. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/custom-error-definition.md - 'unicorn/custom-error-definition': 'error', - - // Prefer `String#startsWith` & `String#endsWith` over more complex alternatives. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-starts-ends-with.md - 'unicorn/prefer-starts-ends-with': 'error', - - // Enforce throwing TypeError in type checking conditions. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-type-error.md - 'unicorn/prefer-type-error': 'error', - - // Prevents passing a function reference directly to iterator methods. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-fn-reference-in-iterator.md - 'unicorn/no-fn-reference-in-iterator': 'off', - - // Enforce importing index files with `.` instead of `./index`. (fixable) - // But we should be explicit. We know it is working without that, - // but at least it is good for newcomers. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/import-index.md - 'unicorn/import-index': 'off', - - // Enforce the use of new for all builtins, except String, Number and Boolean. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/new-for-builtins.md - 'unicorn/new-for-builtins': 'error', - - // Enforce the use of regex shorthands to improve readability. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/regex-shorthand.md - 'unicorn/regex-shorthand': 'error', - - // Prefer the spread operator over `Array.from()`. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-spread.md - 'unicorn/prefer-spread': 'error', - - // Enforce passing a message value when throwing a built-in error. - // "Be explicit" is our motto. Makes errors more useful. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/error-message.md - 'unicorn/error-message': 'error', - - // Disallow unsafe regular expressions. - // Don't allow potential catastrophic crashes, - // slow behaving and downtimes. You still can disable that - // and do whatever you want, but that will be explicit and visible. - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-unsafe-regex.md - 'unicorn/no-unsafe-regex': 'error', - - // Prefer `addEventListener` over `on`-functions in DOM APIs. (fixable) - // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-add-event-listener.md - 'unicorn/prefer-add-event-listener': 'error', - }, -}; diff --git a/test/index.mjs b/test/index.js similarity index 67% rename from test/index.mjs rename to test/index.js index 8c37e0d..7e1d4e2 100644 --- a/test/index.mjs +++ b/test/index.js @@ -1,4 +1,4 @@ -import test from 'asia'; +const test = require('asia'); test('xaxa', (t) => { console.log('yeah');