-
-
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.
* Fix running this rule on Angular ESLint 13. * Fix CI.
- Loading branch information
Showing
8 changed files
with
85 additions
and
12 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
"jerone", | ||
"lcov", | ||
"postpack", | ||
"rimraf", | ||
"SARIF", | ||
"Snyk", | ||
"sonarcloud", | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,64 @@ | ||
// The method `ensureTemplateParser` is exported since ESLint Angular v14.4.0. | ||
// Any version before that requires the fallback. | ||
// See https://github.com/angular-eslint/angular-eslint/issues/888 | ||
// Copied from https://github.com/angular-eslint/angular-eslint/blob/025ad9df4006ccd482b85df93ef52a0d5ebfa29d/packages/utils/src/eslint-plugin-template/parser-services.ts#L28-L45 | ||
// Use `import { ensureTemplateParser } from "@angular-eslint/utils";` once ESLint Angular < v14.4.0 is dropped. | ||
|
||
import type { | ||
ParseSourceSpan, | ||
TmplAstElement, | ||
} from "@angular-eslint/bundled-angular-compiler"; | ||
import type { TSESLint, TSESTree } from "@typescript-eslint/utils"; | ||
|
||
export interface TemplateParserServices { | ||
convertNodeSourceSpanToLoc: ( | ||
sourceSpan: ParseSourceSpan, | ||
) => TSESTree.SourceLocation; | ||
convertElementSourceSpanToLoc: ( | ||
context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>, | ||
node: TmplAstElement, | ||
) => TSESTree.SourceLocation; | ||
} | ||
|
||
/** | ||
* Utility for rule authors to ensure that their rule is correctly being used with @angular-eslint/template-parser | ||
* If @angular-eslint/template-parser is not the configured parser when the function is invoked it will throw | ||
*/ | ||
export function ensureTemplateParser( | ||
context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>, | ||
): void { | ||
try { | ||
import("@angular-eslint/utils") | ||
.then(({ default: utils }) => { | ||
try { | ||
utils.ensureTemplateParser(context); | ||
} catch { | ||
ensureTemplateParserFallback(context); | ||
} | ||
}) | ||
.catch(() => { | ||
ensureTemplateParserFallback(context); | ||
}); | ||
} catch { | ||
ensureTemplateParserFallback(context); | ||
} | ||
} | ||
|
||
function ensureTemplateParserFallback( | ||
context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>, | ||
): void { | ||
if ( | ||
!(context.parserServices as unknown as TemplateParserServices) | ||
?.convertNodeSourceSpanToLoc || | ||
!(context.parserServices as unknown as TemplateParserServices) | ||
?.convertElementSourceSpanToLoc | ||
) { | ||
/** | ||
* The user needs to have configured "parser" in their eslint config and set it | ||
* to @angular-eslint/template-parser | ||
*/ | ||
throw new Error( | ||
"You have used a rule which requires '@angular-eslint/template-parser' to be used as the 'parser' in your ESLint 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { TSESLint } from "@typescript-eslint/utils"; | ||
|
||
// See explanation in `./src/lib/external/ensure-template-parser.ts` why this typing is needed. | ||
declare module "@angular-eslint/utils" { | ||
export function ensureTemplateParser( | ||
context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>, | ||
): void; | ||
} |