diff --git a/CHANGELOG.md b/CHANGELOG.md index 3897a3b81b..bac6b00404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ### Fixed - `importType`: avoid crashing on a non-string' ([#2305], thanks [@ljharb]) +- [`first`]: prevent crash when parsing angular templates ([#2210], thanks [@ljharb]) ### Changed - [`no-default-import`]: report on the token "default" instead of the entire node ([#2299], thanks [@pmcelhaney]) @@ -1227,6 +1228,7 @@ for info on changes for earlier releases. [#164]: https://github.com/import-js/eslint-plugin-import/pull/164 [#157]: https://github.com/import-js/eslint-plugin-import/pull/157 [#2255]: https://github.com/import-js/eslint-plugin-import/issues/2255 +[#2210]: https://github.com/import-js/eslint-plugin-import/issues/2210 [#2201]: https://github.com/import-js/eslint-plugin-import/issues/2201 [#2199]: https://github.com/import-js/eslint-plugin-import/issues/2199 [#2161]: https://github.com/import-js/eslint-plugin-import/issues/2161 diff --git a/package.json b/package.json index 98816bd227..a48f86b225 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ }, "homepage": "https://github.com/import-js/eslint-plugin-import", "devDependencies": { + "@angular-eslint/template-parser": "^13.0.1", "@eslint/import-test-order-redirect-scoped": "file:./tests/files/order-redirect-scoped", "@test-scope/some-module": "file:./tests/files/symlinked-module", "@typescript-eslint/parser": "^2.23.0 || ^3.3.0 || ^4.29.3", diff --git a/src/rules/first.js b/src/rules/first.js index 087b840cb8..285a377f27 100644 --- a/src/rules/first.js +++ b/src/rules/first.js @@ -31,6 +31,9 @@ module.exports = { return { 'Program': function (n) { const body = n.body; + if (!body) { + return; + } const absoluteFirst = context.options[0] === 'absolute-first'; const message = 'Import in body of module; reorder to top.'; const sourceCode = context.getSourceCode(); diff --git a/tests/files/component.html b/tests/files/component.html new file mode 100644 index 0000000000..b63f55e0b2 --- /dev/null +++ b/tests/files/component.html @@ -0,0 +1,139 @@ +
+ + + + + + + + +

Welcome to {{ title }}!

+
+
+

Resources & Tools

+

Thank you for using and showing some ♥ for Nx.

+
+ + If you like Nx, please give it a star: +
+ + + + + Star +
+
+
+

Here are some links to help you get started.

+ +

Next Steps

+

Here are some things you can do with Nx.

+
+ Add UI library +
+  # Generate UI lib
+  nx g @nrwl/angular:lib ui
+
+  # Add a component
+  nx g @nrwl/angular:component xyz --project ui
+
+
+ View dependency graph +
nx dep-graph
+
+
+ Run affected commands +
+  # see what's been affected by changes
+  nx affected:dep-graph
+
+  # run tests for current changes
+  nx affected:test
+
+  # run e2e tests for current changes
+  nx affected:e2e
+  
+
+
+ diff --git a/tests/src/rules/first.js b/tests/src/rules/first.js index 05328e51e9..85643fe9fa 100644 --- a/tests/src/rules/first.js +++ b/tests/src/rules/first.js @@ -1,4 +1,6 @@ import { test, getTSParsers } from '../utils'; +import fs from 'fs'; +import path from 'path'; import { RuleTester } from 'eslint'; @@ -21,6 +23,11 @@ ruleTester.run('first', rule, { code: "'use directive';\ import { x } from 'foo';", }), + test({ + // issue #2210 + code: String(fs.readFileSync(path.join(__dirname, '../../files/component.html'))), + parser: require.resolve('@angular-eslint/template-parser'), + }), ], invalid: [ test({