Skip to content

Commit

Permalink
enforce cjs (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan authored Aug 25, 2021
1 parent d62679f commit f091238
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./src/eslintrc.cjs')
1 change: 0 additions & 1 deletion .eslintrc.js

This file was deleted.

17 changes: 13 additions & 4 deletions bin/install.js → bin/install.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path')

const pkgUp = require('pkg-up')

const ESLINTRC_YAML_CONTENT = `
const ESLINTRC_CJS_CONTENT = `
const rules = {
}
Expand All @@ -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 })
Expand All @@ -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
}
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -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'"
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
File renamed without changes.
7 changes: 5 additions & 2 deletions src/eslintrc.js → src/eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -21,6 +21,9 @@ const ESLINT_RC = {
modules: true,
},
ecmaVersion: 6,
extraFileExtensions: [
'.cjs',
],
project: 'tsconfig.json',
sourceType: 'module',
},
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/detect-patterns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import glob from 'glob'
import { CLIEngine } from 'eslint'

const cli = new CLIEngine({
configFile: '.eslintrc.js',
configFile: '.eslintrc.cjs',
useEslintrc: false,
})

Expand Down
5 changes: 3 additions & 2 deletions tests/fixtures/good-patterns/brace-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion tests/fixtures/good-patterns/env-node.ts
Original file line number Diff line number Diff line change
@@ -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,
)
Expand Down

0 comments on commit f091238

Please sign in to comment.