Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ota-meshi/astro-eslint-parser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: ota-meshi/astro-eslint-parser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.1
Choose a head ref
  • 2 commits
  • 11 files changed
  • 3 contributors

Commits on Apr 26, 2024

  1. fix: crash in scope analysis when using espree (#318)

    * fix: crash in scope analysis when using espree
    
    * fix
    
    * fix
    
    * Create chilly-numbers-smell.md
    ota-meshi authored Apr 26, 2024
    Copy the full SHA
    7126ccc View commit details
  2. chore: release astro-eslint-parser (#319)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Apr 26, 2024
    Copy the full SHA
    20dbf40 View commit details
29 changes: 5 additions & 24 deletions .github/workflows/NodeCI.yml
Original file line number Diff line number Diff line change
@@ -25,34 +25,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x]
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Packages
run: npm install --legacy-peer-deps
- name: Test
run: npm test
test-for-old-node:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install old versions
run: |+
npm i -D @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 --legacy-peer-deps
npx rimraf node_modules
- name: Install Packages
run: npm install --legacy-peer-deps
run: npm install -f
- name: Test
run: npm test
test-for-eslint-v7:
@@ -68,10 +49,10 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install eslint v7
run: |+
npm i -D eslint@7 @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 --legacy-peer-deps
npm i -D eslint@7 @typescript-eslint/parser@5 @typescript-eslint/eslint-plugin@5 -f
npx rimraf node_modules
- name: Install Packages
run: npm install --legacy-peer-deps
run: npm install -f
- name: Test
run: npm test
test-and-coverage:
@@ -84,6 +65,6 @@ jobs:
- name: Test
run: npm run cover
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # v2.2.3
uses: coverallsapp/github-action@v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# astro-eslint-parser

## 1.0.1

### Patch Changes

- [#318](https://github.com/ota-meshi/astro-eslint-parser/pull/318) [`7126ccc`](https://github.com/ota-meshi/astro-eslint-parser/commit/7126ccc91e91f8caed2eda1460f47364ebe462cc) Thanks [@ota-meshi](https://github.com/ota-meshi)! - fix: crash in scope analysis when using espree

## 1.0.0

### Major Changes
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astro-eslint-parser",
"version": "1.0.0",
"version": "1.0.1",
"description": "Astro component parser for ESLint",
"main": "lib/index.js",
"module": "lib/index.mjs",
@@ -55,6 +55,7 @@
"astrojs-compiler-sync": "^1.0.0",
"debug": "^4.3.4",
"entities": "^4.5.0",
"eslint-scope": "^8.0.1",
"eslint-visitor-keys": "^4.0.0",
"espree": "^10.0.0",
"globby": "^11.1.0",
45 changes: 40 additions & 5 deletions src/parser/script.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import type { Context } from "../context";
import { debug } from "../debug";
import type { ParserOptionsContext } from "../context/parser-options";
import type {
ParserOptions,
ParserOptionsContext,
} from "../context/parser-options";
import type { ESLintExtendedProgram } from "../types";
import { tsPatch } from "./ts-patch";
import { isEnhancedParserObject } from "../context/resolve-parser/parser-object";
import { analyze } from "@typescript-eslint/scope-manager";
import type { ScopeManager } from "@typescript-eslint/scope-manager";
import { analyze as analyzeForTypeScript } from "@typescript-eslint/scope-manager";
import { analyze as analyzeForEcmaScript } from "eslint-scope";
import { KEYS } from "../visitor-keys";
import { getKeys } from "../traverse";
/**
* Parse for script
*/
@@ -17,17 +24,45 @@ export function parseScript(

const parserOptions = parserOptionsCtx.parserOptions;
if (!result.scopeManager && parserOptions.eslintScopeManager) {
result.scopeManager = analyze(result.ast, {
ecmaVersion: 1e8,
result.scopeManager = analyzeScope(result, parserOptions);
}

return result;
}

/**
* Analyze scope
*/
function analyzeScope(
result: ESLintExtendedProgram,
parserOptions: ParserOptions,
): ScopeManager {
try {
return analyzeForTypeScript(result.ast, {
globalReturn: parserOptions.ecmaFeatures?.globalReturn,
jsxPragma: parserOptions.jsxPragma,
jsxFragmentName: parserOptions.jsxFragmentName,
lib: parserOptions.lib,
sourceType: parserOptions.sourceType,
});
} catch {
// ignore
}
const ecmaFeatures = parserOptions.ecmaFeatures || {};

return result;
return analyzeForEcmaScript(result.ast, {
ignoreEval: true,
nodejsScope: ecmaFeatures.globalReturn,
impliedStrict: ecmaFeatures.impliedStrict as never,
ecmaVersion: 1e8,
sourceType:
parserOptions.sourceType === "commonjs"
? "script"
: parserOptions.sourceType || "script",
// @ts-expect-error -- Type bug?
childVisitorKeys: result.visitorKeys || KEYS,
fallback: getKeys,
}) as ScopeManager;
}

/**
5 changes: 5 additions & 0 deletions tests/fixtures/parser/ast/js-jsx01-requirements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scope": {
"@typescript-eslint/parser" : ">=7"
}
}
181 changes: 180 additions & 1 deletion tests/fixtures/parser/ast/js-jsx01-scope-output.json
Original file line number Diff line number Diff line change
@@ -1 +1,180 @@
null
{
"type": "global",
"variables": [],
"references": [],
"childScopes": [
{
"type": "module",
"variables": [
{
"name": "MyComponent",
"identifiers": [
{
"type": "Identifier",
"name": "MyComponent",
"range": [
11,
22
],
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 18
}
}
}
],
"defs": [
{
"type": "ImportBinding",
"name": {
"type": "Identifier",
"name": "MyComponent",
"range": [
11,
22
],
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 18
}
}
},
"node": {
"type": "ImportDefaultSpecifier",
"local": {
"type": "Identifier",
"name": "MyComponent",
"range": [
11,
22
],
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 18
}
}
},
"range": [
11,
22
],
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 18
}
}
}
}
],
"references": [
{
"identifier": {
"type": "JSXIdentifier",
"name": "MyComponent",
"range": [
57,
68
],
"loc": {
"start": {
"line": 5,
"column": 1
},
"end": {
"line": 5,
"column": 12
}
}
},
"from": "module",
"init": null,
"resolved": {
"type": "Identifier",
"name": "MyComponent",
"range": [
11,
22
],
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 18
}
}
}
}
]
}
],
"references": [
{
"identifier": {
"type": "JSXIdentifier",
"name": "MyComponent",
"range": [
57,
68
],
"loc": {
"start": {
"line": 5,
"column": 1
},
"end": {
"line": 5,
"column": 12
}
}
},
"from": "module",
"init": null,
"resolved": {
"type": "Identifier",
"name": "MyComponent",
"range": [
11,
22
],
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 18
}
}
}
}
],
"childScopes": [],
"through": []
}
],
"through": []
}
19 changes: 19 additions & 0 deletions tests/fixtures/parser/ast/js-test01-input.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
const sidebarSections = [{ text: "foo" }]
---

<nav aria-labelledby="grid-left">
<ul class="nav-groups">
{sidebarSections.map((section) => (
<li>
<div class="nav-group">{section.text}</div>
</li>
))}
</ul>
</nav>

<style>
.nav-groups > li + li {
margin-top: 2rem;
}
</style>
Loading