diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..9d253d1 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1 @@ +module.exports = require('./src/eslintrc.cjs') diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 26a8a48..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./src/eslintrc') diff --git a/bin/install.js b/bin/install.cjs similarity index 62% rename from bin/install.js rename to bin/install.cjs index e8ab592..644c1ea 100755 --- a/bin/install.js +++ b/bin/install.cjs @@ -5,7 +5,7 @@ const path = require('path') const pkgUp = require('pkg-up') -const ESLINTRC_YAML_CONTENT = ` +const ESLINTRC_CJS_CONTENT = ` const rules = { } @@ -15,6 +15,12 @@ module.exports = { } ` +const RC_EXT_LIST = [ + 'cjs', + 'js', + 'yaml', +] + async function main () { const cwd = path.join(__dirname, '..', '..') const pkgFile = await pkgUp({ cwd }) @@ -23,11 +29,14 @@ async function main () { } const pkgDir = path.dirname(pkgFile) - const eslintRcJsFile = path.join(pkgDir, '.eslintrc.js') + const existRc = RC_EXT_LIST.some(ext => fs.existsSync( + path.join(pkgDir, `.eslintrc.${ext}`) + )) - if (!fs.existsSync(eslintRcJsFile)) { + if (!existRc) { + const eslintRcJsFile = path.join(pkgDir, '.eslintrc.cjs') console.info(`@chatie/eslint-config: auto generated ${eslintRcJsFile}`) - fs.writeFileSync(eslintRcJsFile, ESLINTRC_YAML_CONTENT) + fs.writeFileSync(eslintRcJsFile, ESLINTRC_CJS_CONTENT) } return 0 } diff --git a/package.json b/package.json index edb7fbf..7f1df43 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "@chatie/eslint-config", - "version": "0.12.5", + "version": "0.13.0", "description": "ESLint Sharable Configurations and Rules in Chatie Organization", - "main": "src/eslintrc.js", + "main": "./src/eslintrc.cjs", "scripts": { "dist": "echo dist", "pack": "npm pack", - "postinstall": "node bin/install.js", - "lint": "eslint src/**/*.js", + "postinstall": "node bin/install.cjs", + "lint": "eslint src/**/*.*js", "test:pack": "bash -x scripts/npm-pack-testing.sh", "test": "npm run lint && npm run test:unit", "test:unit": "blue-tape -r ts-node/register 'src/**/*.spec.ts' 'src/*.spec.ts' 'tests/*.spec.ts' 'tests/**/*.spec.ts'" @@ -31,14 +31,14 @@ "homepage": "https://github.com/Chatie/eslint-config#readme", "peerDependencies": {}, "dependencies": { - "@typescript-eslint/eslint-plugin": "^4.14.2", - "@typescript-eslint/eslint-plugin-tslint": "^4.14.2", + "@typescript-eslint/eslint-plugin": "^4.29.3", + "@typescript-eslint/eslint-plugin-tslint": "^4.29.3", "@typescript-eslint/parser": "^4.29.3", "@wwwouter/tslint-contrib": "^1.0.0", "babel-eslint": "^10.1.0", - "eslint": "^7.19.0", - "eslint-config-standard": "^16.0.2", - "eslint-plugin-import": "^2.22.1", + "eslint": "^7.32.0", + "eslint-config-standard": "^16.0.3", + "eslint-plugin-import": "^2.24.2", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.0", "eslint-plugin-standard": "^5.0.0", @@ -52,9 +52,9 @@ "@chatie/git-scripts": "^0.6.2", "@chatie/semver": "^0.4.7", "@chatie/tsconfig": "^0.16.2", - "@types/eslint": "^7.2.6", - "@types/glob": "^7.1.3", - "glob": "^7.1.6", + "@types/eslint": "^7.28.0", + "@types/glob": "^7.1.4", + "glob": "^7.1.7", "tstest": "^0.4.10" }, "publishConfig": { diff --git a/src/eslint-rules.js b/src/eslint-rules.cjs similarity index 100% rename from src/eslint-rules.js rename to src/eslint-rules.cjs diff --git a/src/eslintrc.js b/src/eslintrc.cjs similarity index 78% rename from src/eslintrc.js rename to src/eslintrc.cjs index 899591d..4c5b35b 100644 --- a/src/eslintrc.js +++ b/src/eslintrc.cjs @@ -1,5 +1,5 @@ -const { ESLINT_RULES } = require('./eslint-rules') -const { TSLINT_CONFIG } = require('./tslint-config') +const { ESLINT_RULES } = require('./eslint-rules.cjs') +const { TSLINT_CONFIG } = require('./tslint-config.cjs') const rules = { ...ESLINT_RULES, @@ -21,6 +21,9 @@ const ESLINT_RC = { modules: true, }, ecmaVersion: 6, + extraFileExtensions: [ + '.cjs', + ], project: 'tsconfig.json', sourceType: 'module', }, diff --git a/src/tslint-config.js b/src/tslint-config.cjs similarity index 100% rename from src/tslint-config.js rename to src/tslint-config.cjs diff --git a/tests/detect-patterns.spec.ts b/tests/detect-patterns.spec.ts index b9a8ae6..51445f4 100755 --- a/tests/detect-patterns.spec.ts +++ b/tests/detect-patterns.spec.ts @@ -10,7 +10,7 @@ import glob from 'glob' import { CLIEngine } from 'eslint' const cli = new CLIEngine({ - configFile: '.eslintrc.js', + configFile: '.eslintrc.cjs', useEslintrc: false, }) diff --git a/tests/fixtures/good-patterns/brace-style.ts b/tests/fixtures/good-patterns/brace-style.ts index d9c7d74..638fd28 100644 --- a/tests/fixtures/good-patterns/brace-style.ts +++ b/tests/fixtures/good-patterns/brace-style.ts @@ -3,5 +3,6 @@ */ const n = 42 -if (n === 42) { console.info(n) } -else { console.info(n + 1) } +if (n === 42) { console.info(n) } else { + console.info(n + 1) +} diff --git a/tests/fixtures/good-patterns/env-node.ts b/tests/fixtures/good-patterns/env-node.ts index 0f9af5f..581d907 100644 --- a/tests/fixtures/good-patterns/env-node.ts +++ b/tests/fixtures/good-patterns/env-node.ts @@ -1,7 +1,9 @@ /** * https://stackoverflow.com/q/64089216/1123955 */ -const timer: NodeJS.Timeout = setTimeout( +// Huan(202108): FIXME: This is a temporary workaround for the above issue. +// const timer: NodeJS.Timeout = setTimeout( +const timer = setTimeout( () => { console.info('timeout') }, 100, )