Skip to content

Commit 1a2ecce

Browse files
committedJun 10, 2022
feat: support eslint 8 by excluding coffee if the version is >=8
1 parent 169cbba commit 1a2ecce

File tree

4 files changed

+166
-47
lines changed

4 files changed

+166
-47
lines changed
 

‎package.json

+3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@
3939
"eslint-plugin-yaml": "^0.5.0",
4040
"prettier": "2.4.1",
4141
"read-pkg-up": "^7",
42+
"semver": "^7.3.7",
4243
"typescript": "^4"
4344
},
4445
"devDependencies": {
46+
"@types/node": "^17.0.41",
47+
"@types/semver": "^7.3.9",
4548
"eslint": "^7",
4649
"execa": "^5.1.1",
4750
"gitly": "^2.1.6",

‎pnpm-lock.yaml

+139-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/eslint-version.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const child_process = require("child_process")
2+
3+
function getEslintVersion() {
4+
if (process.argv[1].includes("eslint.js")) {
5+
const eslintVersion = child_process.execFileSync(process.argv[0], [process.argv[1], "--version"], {
6+
encoding: "utf8",
7+
stdio: "pipe",
8+
})
9+
return eslintVersion
10+
} else {
11+
return require("eslint/package.json").version
12+
}
13+
}
14+
15+
exports.getEslintVersion = getEslintVersion

‎src/index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@ const { csonConfig } = require("./cson")
66
const { yamlConfig } = require("./yaml")
77
const { htmlConfig } = require("./html")
88
const { pluginImportSettings } = require("./plugin-import-rules")
9+
const semverLt = require("semver/functions/lt")
10+
const { getEslintVersion } = require("./eslint-version")
911

1012
const overrides = [tsConfig, jsonConfig, yamlConfig, htmlConfig]
1113

1214
// add coffee if installed
1315
if (coffeeConfig !== {}) {
1416
try {
15-
const found = require.resolve("eslint-plugin-coffee")
16-
if (found) {
17-
overrides.push(coffeeConfig, csonConfig)
17+
// check if the eslint version is >= 8
18+
if (semverLt(getEslintVersion(), "8.0.0")) {
19+
// if so try adding the coffee plugin
20+
const found = require.resolve("eslint-plugin-coffee")
21+
if (found) {
22+
overrides.push(coffeeConfig, csonConfig)
23+
}
1824
}
1925
} catch (_err) {
2026
// optional plugin

0 commit comments

Comments
 (0)
Please sign in to comment.