diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 12b1e856..77240a0c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,7 +1,7 @@ { "packages/compat": "1.1.1", - "packages/config-array": "0.17.0", - "packages/core": "0.2.0", - "packages/migrate-config": "1.1.2", + "packages/config-array": "0.17.1", + "packages/core": "0.3.0", + "packages/migrate-config": "1.2.0", "packages/object-schema": "2.1.4" } diff --git a/packages/config-array/CHANGELOG.md b/packages/config-array/CHANGELOG.md index c3cced4f..e9f29256 100644 --- a/packages/config-array/CHANGELOG.md +++ b/packages/config-array/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.17.1](https://github.com/eslint/rewrite/compare/config-array-v0.17.0...config-array-v0.17.1) (2024-07-22) + + +### Bug Fixes + +* `basePath` directory can never be ignored ([#92](https://github.com/eslint/rewrite/issues/92)) ([c94ab2d](https://github.com/eslint/rewrite/commit/c94ab2dea6410698a4b6814f921b39774b0e56ab)) + ## [0.17.0](https://github.com/eslint/rewrite/compare/config-array-v0.16.0...config-array-v0.17.0) (2024-06-26) diff --git a/packages/config-array/jsr.json b/packages/config-array/jsr.json index ed4a986d..98b8d937 100644 --- a/packages/config-array/jsr.json +++ b/packages/config-array/jsr.json @@ -1,6 +1,6 @@ { "name": "@eslint/config-array", - "version": "0.17.0", + "version": "0.17.1", "exports": "./dist/esm/index.js", "publish": { "include": [ diff --git a/packages/config-array/package.json b/packages/config-array/package.json index 5e7f838e..0315920d 100644 --- a/packages/config-array/package.json +++ b/packages/config-array/package.json @@ -1,6 +1,6 @@ { "name": "@eslint/config-array", - "version": "0.17.0", + "version": "0.17.1", "description": "General purpose glob-based configuration matching.", "author": "Nicholas C. Zakas", "type": "module", diff --git a/packages/config-array/src/config-array.js b/packages/config-array/src/config-array.js index 2dce1e7b..51a525b1 100644 --- a/packages/config-array/src/config-array.js +++ b/packages/config-array/src/config-array.js @@ -1024,6 +1024,11 @@ export class ConfigArray extends Array { .relative(this.basePath, directoryPath) .replace(/\\/gu, "/"); + // basePath directory can never be ignored + if (relativeDirectoryPath === "") { + return false; + } + if (relativeDirectoryPath.startsWith("..")) { return true; } diff --git a/packages/config-array/tests/config-array.test.js b/packages/config-array/tests/config-array.test.js index c5270ab1..11a0961d 100644 --- a/packages/config-array/tests/config-array.test.js +++ b/packages/config-array/tests/config-array.test.js @@ -1071,6 +1071,64 @@ describe("ConfigArray", () => { ); }); + // https://github.com/eslint/eslint/issues/18706 + it("should disregard `/` in global `ignores`", () => { + configs = new ConfigArray( + [ + { + ignores: ["/"], + }, + { + files: ["**/*.js"], + defs: { + severity: "error", + }, + }, + ], + { basePath, schema }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfig(path.resolve(basePath, "file.js")).defs + .severity, + "error", + ); + + assert.strictEqual( + configs.getConfig( + path.resolve(basePath, "subdir", "file.js"), + ).defs.severity, + "error", + ); + }); + + it("should return config for an unignored file in basePath when all files are initially ignored by '**'", () => { + configs = new ConfigArray( + [ + { + ignores: ["**", "!file.js"], + }, + { + files: ["**/*.js"], + defs: { + severity: "error", + }, + }, + ], + { basePath, schema }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfig(path.resolve(basePath, "file.js")).defs + .severity, + "error", + ); + }); + // https://github.com/eslint/eslint/issues/17103 describe("ignores patterns should be properly applied", () => { it("should return undefined when a filename matches an ignores pattern but not a files pattern", () => { @@ -2701,6 +2759,23 @@ describe("ConfigArray", () => { ); }); + it("should always return false for basePath", () => { + configs = new ConfigArray( + [ + { + ignores: ["**", "/"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual(configs.isDirectoryIgnored(basePath), false); + }); + it("should return true when a directory is in ignores", () => { configs = new ConfigArray( [ diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 7a66ec37..3f3292b3 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## [0.3.0](https://github.com/eslint/rewrite/compare/core-v0.2.0...core-v0.3.0) (2024-07-22) + + +### ⚠ BREAKING CHANGES + +* Add getLoc/getRange to SourceCode interface ([#89](https://github.com/eslint/rewrite/issues/89)) + +### Features + +* Add getLoc/getRange to SourceCode interface ([#89](https://github.com/eslint/rewrite/issues/89)) ([d51f979](https://github.com/eslint/rewrite/commit/d51f9791aecd9aa80136a0926e57549df9e25ab3)) + ## [0.2.0](https://github.com/eslint/rewrite/compare/core-v0.1.0...core-v0.2.0) (2024-07-11) diff --git a/packages/core/jsr.json b/packages/core/jsr.json index f655c3f5..8ec31aa3 100644 --- a/packages/core/jsr.json +++ b/packages/core/jsr.json @@ -1,6 +1,6 @@ { "name": "@eslint/core", - "version": "0.2.0", + "version": "0.3.0", "exports": "./src/types.ts", "publish": { "include": [ diff --git a/packages/core/package.json b/packages/core/package.json index 82be3100..a2b2930c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@eslint/core", - "version": "0.2.0", + "version": "0.3.0", "description": "Runtime-agnostic core of ESLint", "type": "module", "types": "./src/types.ts", diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 7c217c50..25a8663b 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -31,12 +31,11 @@ export interface FileProblem { //------------------------------------------------------------------------------ /** - * Represents an AST node or token with location information. + * Represents an AST node or token with location information in ESLint format. */ export interface SyntaxElement { loc: SourceLocation; - range: [number, number]; - [key: string]: any; + range: SourceRange; } /** @@ -48,13 +47,34 @@ export interface SourceLocation { } /** - * Represents a location coordinate inside the source. + * Represents the start and end coordinates of a node inside the source with an offset. + */ +export interface SourceLocationWithOffset { + start: PositionWithOffset; + end: PositionWithOffset; +} + +/** + * Represents a location coordinate inside the source. ESLint-style formats + * have just `line` and `column` while others may have `offset` as well. */ export interface Position { line: number; column: number; } +/** + * Represents a location coordinate inside the source with an offset. + */ +export interface PositionWithOffset extends Position { + offset: number; +} + +/** + * Represents a range of characters in the source. + */ +export type SourceRange = [number, number]; + //------------------------------------------------------------------------------ // Config //------------------------------------------------------------------------------ @@ -157,8 +177,8 @@ export interface Language { */ matchesSelectorClass?( className: string, - node: SyntaxElement, - ancestry: Array, + node: object, + ancestry: Array, ): boolean; /** @@ -222,7 +242,7 @@ export interface File { /** * Represents the successful result of parsing a file. */ -export interface OkParseResult { +export interface OkParseResult { /** * Indicates if the parse was successful. If true, the parse was successful * and ESLint should continue on to create a SourceCode object and run rules; @@ -234,7 +254,7 @@ export interface OkParseResult { /** * The abstract syntax tree created by the parser. (only when ok: true) */ - ast: SyntaxElement; + ast: T; /** * Any additional data that the parser wants to provide. @@ -265,7 +285,9 @@ export interface NotOkParseResult { [key: string]: any; } -export type ParseResult = OkParseResult | NotOkParseResult; +export type ParseResult = + | OkParseResult + | NotOkParseResult; /** * Represents inline configuration found in the source code. @@ -291,7 +313,7 @@ interface SourceCodeBase { /** * Root of the AST. */ - ast: SyntaxElement; + ast: object; /** * The traversal path that tools should take when evaluating the AST. @@ -300,6 +322,16 @@ interface SourceCodeBase { */ visitorKeys?: Record>; + /** + * Retrieves the equivalent of `loc` for a given node or token. + */ + getLoc(nodeOrToken: object): SourceLocation; + + /** + * Retrieves the equivalent of `range` for a given node or token. + */ + getRange(nodeOrToken: object): SourceRange; + /** * Traversal of AST. */ @@ -323,7 +355,7 @@ interface SourceCodeBase { * Returns an array of all inline configuration nodes found in the * source code. */ - getInlineConfigNodes?(): Array; + getInlineConfigNodes?(): Array; /** * Applies configuration found inside of the source code. This method is only @@ -370,7 +402,7 @@ export type SourceCode = TextSourceCode | BinarySourceCode; */ export interface VisitTraversalStep { kind: 1; - target: SyntaxElement; + target: object; phase: 1 /* enter */ | 2 /* exit */; args: Array; } @@ -399,7 +431,7 @@ export interface Directive { /** * The node of the directive. May be in the AST or a comment/token. */ - node: SyntaxElement; + node: object; /** * The value of the directive. diff --git a/packages/migrate-config/CHANGELOG.md b/packages/migrate-config/CHANGELOG.md index 91040815..c4900c1b 100644 --- a/packages/migrate-config/CHANGELOG.md +++ b/packages/migrate-config/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.2.0](https://github.com/eslint/rewrite/compare/migrate-config-v1.1.2...migrate-config-v1.2.0) (2024-07-22) + + +### Features + +* `eslint-plugin-react` supports ESLint v9 ([#91](https://github.com/eslint/rewrite/issues/91)) ([7664bf8](https://github.com/eslint/rewrite/commit/7664bf801995c4a6a15d600b4542d47075fc6194)) + ## [1.1.2](https://github.com/eslint/rewrite/compare/migrate-config-v1.1.1...migrate-config-v1.1.2) (2024-07-11) diff --git a/packages/migrate-config/package.json b/packages/migrate-config/package.json index 055e47d2..c2539fe0 100644 --- a/packages/migrate-config/package.json +++ b/packages/migrate-config/package.json @@ -1,6 +1,6 @@ { "name": "@eslint/migrate-config", - "version": "1.1.2", + "version": "1.2.0", "description": "Configuration migration for ESLint", "type": "module", "bin": { diff --git a/packages/migrate-config/src/compat-plugins.js b/packages/migrate-config/src/compat-plugins.js index b1881985..d9ef2533 100644 --- a/packages/migrate-config/src/compat-plugins.js +++ b/packages/migrate-config/src/compat-plugins.js @@ -6,6 +6,5 @@ export default [ "eslint-plugin-ava", "eslint-plugin-react-hooks", - "eslint-plugin-react", "eslint-plugin-import", ]; diff --git a/packages/migrate-config/tests/fixtures/import-duplicate/.eslintrc.cjs b/packages/migrate-config/tests/fixtures/import-duplicate/.eslintrc.cjs index b5b0c137..6bfce2be 100644 --- a/packages/migrate-config/tests/fixtures/import-duplicate/.eslintrc.cjs +++ b/packages/migrate-config/tests/fixtures/import-duplicate/.eslintrc.cjs @@ -1,5 +1,5 @@ module.exports = { - plugins: ["react"], + plugins: ["import"], overrides: [ { plugins: ["react-hooks"], diff --git a/packages/migrate-config/tests/fixtures/import-duplicate/expected.cjs b/packages/migrate-config/tests/fixtures/import-duplicate/expected.cjs index 2d52f46c..f838cef3 100644 --- a/packages/migrate-config/tests/fixtures/import-duplicate/expected.cjs +++ b/packages/migrate-config/tests/fixtures/import-duplicate/expected.cjs @@ -1,4 +1,4 @@ -const react = require("eslint-plugin-react"); +const _import = require("eslint-plugin-import"); const { fixupPluginRules, @@ -8,7 +8,7 @@ const reactHooks = require("eslint-plugin-react-hooks"); module.exports = [{ plugins: { - react: fixupPluginRules(react), + import: fixupPluginRules(_import), }, }, { plugins: { diff --git a/packages/migrate-config/tests/fixtures/import-duplicate/expected.mjs b/packages/migrate-config/tests/fixtures/import-duplicate/expected.mjs index 48194124..4c962df2 100644 --- a/packages/migrate-config/tests/fixtures/import-duplicate/expected.mjs +++ b/packages/migrate-config/tests/fixtures/import-duplicate/expected.mjs @@ -1,10 +1,10 @@ -import react from "eslint-plugin-react"; +import _import from "eslint-plugin-import"; import { fixupPluginRules } from "@eslint/compat"; import reactHooks from "eslint-plugin-react-hooks"; export default [{ plugins: { - react: fixupPluginRules(react), + import: fixupPluginRules(_import), }, }, { plugins: {