Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ jobs:
run: npm run build
- name: Run tests
run: npm run test
are-the-types-wrong:
name: Are the types wrong?
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 'lts/*'
- name: Install dependencies
run: npm install
- name: Are the types wrong?
run: npm run lint:types
32 changes: 23 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { defineConfig, globalIgnores } from "eslint/config";
import eslintConfigESLint from "eslint-config-eslint";
import eslintConfigESLintFormatting from "eslint-config-eslint/formatting";
import eslintPluginChaiFriendly from "eslint-plugin-chai-friendly";
import * as expectType from "eslint-plugin-expect-type";
import globals from "globals";
import tsParser from "@typescript-eslint/parser";

export default defineConfig([
globalIgnores([
Expand All @@ -11,23 +13,20 @@ export default defineConfig([
"**/coverage/",
"packages/espree/tools/create-test-example.js"
]),
eslintConfigESLint,
eslintConfigESLintFormatting,
{
files: ["packages/*/tests/lib/**"],
files: ["**/*.{,c}js"],
extends: [eslintConfigESLint, eslintConfigESLintFormatting]
},
{
files: ["packages/*/tests/**/*.test.{,c}js"],
languageOptions: {
globals: {
...globals.mocha
}
}
},
{
files: ["packages/eslint-scope/tests/**"],
languageOptions: {
globals: {
...globals.mocha
}
},
files: ["packages/eslint-scope/tests/**/*.{,c}js"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
files: ["packages/eslint-scope/tests/**/*.{,c}js"],
files: ["packages/eslint-scope/tests/**/*.test.{,c}js"],

Would it make sense to restrict its scope to test files? The related setups, like the mocha global and chai-friendly, seem to be needed only for test files, not for test helpers like packages/eslint-scope/tests/util/ecma-version.js and packages/eslint-scope/tests/util/espree.js.

Copy link
Member Author

@fasttime fasttime Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I've addressed this in 068df91. Please, have a look!

plugins: {
"chai-friendly": eslintPluginChaiFriendly
},
Expand Down Expand Up @@ -68,6 +67,21 @@ export default defineConfig([
}
}
},
{
files: ["packages/eslint-scope/tests/types/*.{,c}ts"],
languageOptions: {
parser: tsParser,
parserOptions: {
project: ["packages/eslint-scope/tests/types/tsconfig.json"]
}
},
plugins: {
"expect-type": expectType
},
rules: {
"expect-type/expect": "error"
}
},
{
files: ["**/tools/**"],
rules: {
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"test": "npm test --workspaces --if-present",
"build": "npm run build --workspaces --if-present",
"lint": "eslint",
"lint:fix": "eslint --fix"
"lint:fix": "eslint --fix",
"lint:types": "npm run lint:types --workspaces --if-present"
},
"workspaces": [
"packages/*"
Expand All @@ -16,15 +17,17 @@
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.{js,cjs}": [
"*.{js,cjs,ts,cts}": [
"eslint --fix"
]
},
"devDependencies": {
"@typescript-eslint/parser": "^8.47.0",
"c8": "^10.1.3",
"eslint": "^9.35.0",
"eslint-config-eslint": "^13.0.0",
"eslint-plugin-chai-friendly": "^1.0.0",
"eslint-plugin-expect-type": "^0.6.2",
"globals": "^16.0.0",
"lint-staged": "^15.2.0",
"mocha": "^11.1.0",
Expand Down
13 changes: 8 additions & 5 deletions packages/eslint-scope/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ In order to analyze scope, you'll need to have an [ESTree](https://github.com/es
* `sourceType` (default: `"script"`) - The type of JavaScript file to evaluate. Change to `"module"` for ECMAScript module code.
* `childVisitorKeys` (default: `null`) - An object with visitor key information (like [`eslint-visitor-keys`](https://github.com/eslint/js/tree/main/packages/eslint-visitor-keys)). Without this, `eslint-scope` finds child nodes to visit algorithmically. Providing this option is a performance enhancement.
* `fallback` (default: `"iteration"`) - The strategy to use when `childVisitorKeys` is not specified. May be a function.
* `optimistic` (default: `false`) - Set to `true` to enable optimistic scope analysis.
* `jsx` (default: `false`) - Enables the tracking of JSX components as variable references.

Example:
Expand Down Expand Up @@ -100,7 +101,7 @@ The `ScopeManager` class is at the core of eslint-scope and is returned when you
- `inner` - Optional boolean. When `true`, returns the innermost scope, otherwise returns the outermost scope. Default is `false`.
- Returns: The acquired scope or `null` if no scope is found.

- **`acquireAll(node)`**
- **`acquireAll(node)` (Deprecated)**
Acquires all scopes for a given node.
- `node` - The AST node to acquire scopes from.
- Returns: An array of scopes or `undefined` if none are found.
Expand All @@ -120,27 +121,29 @@ The `ScopeManager` class is at the core of eslint-scope and is returned when you
Determines if the global return statement should be allowed.
- Returns: `true` if the global return is enabled.

- **`isModule()`**
- **`isModule()` (Deprecated)**
Checks if the code should be handled as an ECMAScript module.
- Returns: `true` if the sourceType is "module".

- **`isImpliedStrict()`**
- **`isImpliedStrict()` (Deprecated)**
Checks if implied strict mode is enabled.
- Returns: `true` if implied strict mode is enabled.

- **`isStrictModeSupported()`**
- **`isStrictModeSupported()` (Deprecated)**
Checks if strict mode is supported based on ECMAScript version.
- Returns: `true` if the ECMAScript version supports strict mode.

### Scope Objects

Scopes returned by the ScopeManager methods have the following properties:

- `type` - The type of scope (e.g., "function", "block", "global").
- `type` - The type of scope (e.g., `"function"`, `"block"`, `"global"`).
- `isStrict` - `true` if this scope is in strict mode.
- `variables` - Array of variables declared in this scope.
- `set` - A Map of variable names to Variable objects for variables declared in this scope.
- `references` - Array of references in this scope.
- `through` - Array of references in this scope and its child scopes that aren't resolved in this scope or its child scopes.
- `functionExpressionScope` - `true` if this is a `"function-expression-name"` scope.
- `variableScope` - Reference to the closest variable scope.
- `upper` - Reference to the parent scope.
- `childScopes` - Array of child scopes.
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-scope/lib/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@

import Variable from "./variable.js";

/** @import * as types from "eslint-scope" */

// Cannot implement `types.Definition` directly because it contains a union.
/**
* @constructor Definition
* @implements {Omit<types.Definition, never>}
*/
class Definition {
constructor(type, name, node, parent, index, kind) {
Expand Down
Loading