-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for flat config (#139)
* feat: add support for flat config * Create rare-grapes-call.md * fix
- Loading branch information
Showing
15 changed files
with
197 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"eslint-plugin-node-dependencies": minor | ||
--- | ||
|
||
feat: add support for flat config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { ESLint, Linter } from "eslint"; | ||
import recommendedRules from "../rules/recommended"; | ||
import * as jsonParser from "jsonc-eslint-parser"; | ||
export const recommendedConfig = [ | ||
{ | ||
plugins: { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention -- ignore | ||
get "node-dependencies"(): ESLint.Plugin { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore | ||
return require("../../index"); | ||
}, | ||
}, | ||
}, | ||
{ | ||
files: ["**/package.json", "package.json"], | ||
languageOptions: { | ||
parser: jsonParser, | ||
}, | ||
rules: recommendedRules.rules, | ||
}, | ||
] satisfies Linter.FlatConfig[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Linter } from "eslint"; | ||
|
||
export default { | ||
rules: { | ||
// eslint-plugin-node-dependencies rules | ||
"node-dependencies/compat-engines": "error", | ||
"node-dependencies/no-dupe-deps": "error", | ||
"node-dependencies/valid-semver": "error", | ||
} as Linter.RulesRecord, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
tests/fixtures/integrations/eslint-plugin-legacy-config/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"dependencies": { | ||
"semver": "^7.3.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as nodeDependenciesPlugin from "../../../../dist/index.js" | ||
|
||
export default [ | ||
...nodeDependenciesPlugin.configs["flat/recommended"], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,66 @@ | ||
import path from "path"; | ||
import assert from "assert"; | ||
import { getLegacyESLint } from "eslint-compat-utils/eslint"; | ||
import * as eslintModule from "eslint"; | ||
import plugin from "../../lib/index"; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention -- ignore | ||
const ESLint = getLegacyESLint(); | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Tests | ||
// ----------------------------------------------------------------------------- | ||
|
||
const TEST_CWD = path.join(__dirname, "../fixtures/integrations/eslint-plugin"); | ||
const TEST_CWD_FOR_FLAT_CONFIG = path.join( | ||
__dirname, | ||
"../fixtures/integrations/eslint-plugin", | ||
); | ||
const TEST_CWD_FOR_LEGACY_CONFIG = path.join( | ||
__dirname, | ||
"../fixtures/integrations/eslint-plugin-legacy-config", | ||
); | ||
|
||
describe("Integration with eslint-plugin-node-dependencies", () => { | ||
if (!ESLint) { | ||
return; | ||
} | ||
it("should lint without errors", async () => { | ||
const engine = new ESLint({ | ||
cwd: TEST_CWD, | ||
plugins: { | ||
"eslint-plugin-node-dependencies": plugin as never, | ||
}, | ||
describe("Integration with eslint-plugin-node-dependencies", async () => { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention -- ignore | ||
const FlatESLint: typeof eslintModule.ESLint = | ||
// @ts-expect-error -- new API | ||
typeof eslintModule.loadESLint === "function" | ||
? // @ts-expect-error -- new API | ||
await eslintModule.loadESLint({ useFlatConfig: true }) | ||
: null; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention -- ignore | ||
const ESLint: typeof eslintModule.ESLint = | ||
// @ts-expect-error -- new API | ||
typeof eslintModule.loadESLint === "function" | ||
? // @ts-expect-error -- new API | ||
await eslintModule.loadESLint({ useFlatConfig: false }) | ||
: getLegacyESLint(); | ||
if (FlatESLint) { | ||
it("should lint without errors (with flat config)", async () => { | ||
const eslint = new FlatESLint({ | ||
cwd: TEST_CWD_FOR_FLAT_CONFIG, | ||
}); | ||
const results = await eslint.lintFiles(["package.json"]); | ||
|
||
assert.strictEqual(results.length, 1); | ||
assert.deepStrictEqual( | ||
results[0].messages.map((m) => m.ruleId), | ||
["node-dependencies/compat-engines"], | ||
); | ||
}); | ||
const results = await engine.lintFiles(["package.json"]); | ||
} | ||
if (ESLint) { | ||
it("should lint without errors (with legacy config)", async () => { | ||
const engine = new ESLint({ | ||
cwd: TEST_CWD_FOR_LEGACY_CONFIG, | ||
plugins: { | ||
"eslint-plugin-node-dependencies": plugin as never, | ||
}, | ||
}); | ||
const results = await engine.lintFiles(["package.json"]); | ||
|
||
assert.strictEqual(results.length, 1); | ||
assert.deepStrictEqual( | ||
results[0].messages.map((m) => m.ruleId), | ||
["node-dependencies/compat-engines"], | ||
); | ||
}); | ||
assert.strictEqual(results.length, 1); | ||
assert.deepStrictEqual( | ||
results[0].messages.map((m) => m.ruleId), | ||
["node-dependencies/compat-engines"], | ||
); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters