@angular-eslint/utils 17.5.3-alpha.1 → 17.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1 @@
1
1
  # @angular-eslint/utils
2
-
3
- Please see https://github.com/angular-eslint/angular-eslint for full usage instructions and guidance.
4
-
5
- The `@angular-eslint/utils` package is a set of utility functions and types which are used across the `@angular-eslint` packages and are helpful when writing your own custom ESLint rules for Angular workspaces.
@@ -0,0 +1,61 @@
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ /**
3
+ * When leveraging the convertAnnotatedSourceToFailureCase() utility, the
4
+ * following characters are eligible to be used in the source code of expected
5
+ * failure cases within ESLint unit tests in order to provide an easy way to
6
+ * annotate where one or more ESLint errors are expected to occur within that
7
+ * source.
8
+ *
9
+ * See the convertAnnotatedSourceToFailureCase() utility itself for more details.
10
+ */
11
+ export declare const SPECIAL_UNDERLINE_CHARS: readonly ["~", "^", "#", "%", "¶", "*", "¨", "@"];
12
+ type MultipleErrorOptions<TMessageIds extends string> = BaseErrorOptions & {
13
+ readonly messages: readonly (Message<TMessageIds> & {
14
+ readonly char: (typeof SPECIAL_UNDERLINE_CHARS)[number];
15
+ })[];
16
+ };
17
+ type BaseErrorOptions = {
18
+ readonly description: string;
19
+ readonly annotatedSource: string;
20
+ readonly options?: readonly unknown[];
21
+ readonly annotatedOutput?: string;
22
+ readonly filename?: string;
23
+ readonly only?: boolean;
24
+ };
25
+ type Message<TMessageIds extends string> = {
26
+ readonly messageId: TMessageIds;
27
+ readonly data?: Record<string, unknown>;
28
+ readonly suggestions?: TSESLint.SuggestionOutput<TMessageIds>[];
29
+ };
30
+ type SingleErrorOptions<TMessageIds extends string> = BaseErrorOptions & Message<TMessageIds>;
31
+ /**
32
+ * convertAnnotatedSourceToFailureCase() provides an ergonomic way to easily write
33
+ * expected failure cases for ESLint rules by allowing you to directly annotate the
34
+ * source code for the case with one or more of the values in `SPECIAL_UNDERLINE_CHARS`.
35
+ *
36
+ * This not only makes the unit tests easier to write because of the time saved in figuring
37
+ * out location data in terms of lines and columns, but also far easier to read, which is
38
+ * arguably much more important.
39
+ *
40
+ * Here is a real-world example of using the utility:
41
+ *
42
+ * ```ts
43
+ * convertAnnotatedSourceToFailureCase({
44
+ * description: 'should fail when Pipe has no prefix ng',
45
+ * annotatedSource: `
46
+ * @Pipe({
47
+ * name: 'foo-bar'
48
+ * ~~~~~~~~~
49
+ * })
50
+ * class Test {}
51
+ * `,
52
+ * messageId: 'pipePrefix,
53
+ * options: [{ prefixes: ['ng'] }],
54
+ * data: { prefixes: '"ng"' },
55
+ * }),
56
+ * ```
57
+ */
58
+ export declare function convertAnnotatedSourceToFailureCase<TMessageIds extends string>(errorOptions: SingleErrorOptions<TMessageIds>): TSESLint.InvalidTestCase<TMessageIds, readonly unknown[]>;
59
+ export declare function convertAnnotatedSourceToFailureCase<TMessageIds extends string>(errorOptions: MultipleErrorOptions<TMessageIds>): TSESLint.InvalidTestCase<TMessageIds, readonly unknown[]>;
60
+ export {};
61
+ //# sourceMappingURL=convert-annotated-source-to-failure-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-annotated-source-to-failure-case.d.ts","sourceRoot":"","sources":["../src/convert-annotated-source-to-failure-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,mDAS1B,CAAC;AAEX,KAAK,oBAAoB,CAAC,WAAW,SAAS,MAAM,IAAI,gBAAgB,GAAG;IACzE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG;QAClD,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;KACzD,CAAC,EAAE,CAAC;CACN,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IACtC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,KAAK,OAAO,CAAC,WAAW,SAAS,MAAM,IAAI;IACzC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC;CACjE,CAAC;AAEF,KAAK,kBAAkB,CAAC,WAAW,SAAS,MAAM,IAAI,gBAAgB,GACpE,OAAO,CAAC,WAAW,CAAC,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,mCAAmC,CAAC,WAAW,SAAS,MAAM,EAC5E,YAAY,EAAE,kBAAkB,CAAC,WAAW,CAAC,GAC5C,QAAQ,CAAC,eAAe,CAAC,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC;AAC7D,wBAAgB,mCAAmC,CAAC,WAAW,SAAS,MAAM,EAC5E,YAAY,EAAE,oBAAoB,CAAC,WAAW,CAAC,GAC9C,QAAQ,CAAC,eAAe,CAAC,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC"}
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertAnnotatedSourceToFailureCase = exports.SPECIAL_UNDERLINE_CHARS = void 0;
4
+ /**
5
+ * When leveraging the convertAnnotatedSourceToFailureCase() utility, the
6
+ * following characters are eligible to be used in the source code of expected
7
+ * failure cases within ESLint unit tests in order to provide an easy way to
8
+ * annotate where one or more ESLint errors are expected to occur within that
9
+ * source.
10
+ *
11
+ * See the convertAnnotatedSourceToFailureCase() utility itself for more details.
12
+ */
13
+ exports.SPECIAL_UNDERLINE_CHARS = [
14
+ '~',
15
+ '^',
16
+ '#',
17
+ '%',
18
+ '¶',
19
+ '*',
20
+ '¨',
21
+ '@',
22
+ ];
23
+ function convertAnnotatedSourceToFailureCase(errorOptions) {
24
+ const messages = 'messageId' in errorOptions
25
+ ? [{ ...errorOptions, char: '~' }]
26
+ : errorOptions.messages;
27
+ let parsedSource = '';
28
+ const errors = messages.map(({ char: currentValueChar, data, messageId, suggestions }) => {
29
+ const otherChars = messages
30
+ .map(({ char }) => char)
31
+ .filter((char) => char !== currentValueChar);
32
+ const parsedForChar = parseInvalidSource(errorOptions.annotatedSource, currentValueChar, otherChars);
33
+ const { failure: { endPosition, startPosition }, } = parsedForChar;
34
+ parsedSource = parsedForChar.source;
35
+ if (!endPosition || !startPosition) {
36
+ throw Error(`Char '${currentValueChar}' has been specified in \`messages\`, however it is not present in the source of the failure case`);
37
+ }
38
+ return {
39
+ data,
40
+ messageId,
41
+ line: startPosition.line + 1,
42
+ column: startPosition.character + 1,
43
+ endLine: endPosition.line + 1,
44
+ endColumn: endPosition.character + 1,
45
+ suggestions,
46
+ };
47
+ });
48
+ return {
49
+ name: errorOptions.description,
50
+ code: parsedSource,
51
+ filename: errorOptions.filename,
52
+ options: errorOptions.options ?? [],
53
+ errors,
54
+ only: errorOptions.only ?? false,
55
+ output: errorOptions.annotatedOutput
56
+ ? parseInvalidSource(errorOptions.annotatedOutput).source
57
+ : null,
58
+ };
59
+ }
60
+ exports.convertAnnotatedSourceToFailureCase = convertAnnotatedSourceToFailureCase;
61
+ function escapeRegexp(value) {
62
+ return value.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
63
+ }
64
+ /**
65
+ * When testing a failure, we also test to see if the linter will report the correct place where
66
+ * the source code doesn't match the rule.
67
+ *
68
+ * For example, if you use a private property in your template, the linter should report _where_
69
+ * did it happen. Because it's tedious to supply actual line/column number in the spec, we use
70
+ * some custom syntax with "underlining" the problematic part with tildes:
71
+ *
72
+ * ```
73
+ * template: '{{ foo }}'
74
+ * ~~~
75
+ * ```
76
+ *
77
+ * When giving a spec which we expect to fail, we give it "source code" such as above, with tildes.
78
+ * We call this kind of source code "annotated". This source code cannot be compiled (and thus
79
+ * cannot be linted/tested), so we use this function to get rid of tildes, but maintain the
80
+ * information about where the linter is supposed to catch error.
81
+ *
82
+ * The result of the function contains "cleaned" source (`.source`) and a `.failure` object which
83
+ * contains the `.startPosition` and `.endPosition` of the tildes.
84
+ *
85
+ * @param source The annotated source code with tildes.
86
+ * @param specialChar The character to look for; in the above example that's ~.
87
+ * @param otherChars All other characters which should be ignored. Used when asserting multiple
88
+ * failures where there are multiple invalid characters.
89
+ * @returns {{source: string, failure: {message: string, startPosition: null, endPosition: any}}}
90
+ */
91
+ function parseInvalidSource(source, specialChar = '~', otherChars = []) {
92
+ let replacedSource;
93
+ if (otherChars.length === 0) {
94
+ replacedSource = source;
95
+ }
96
+ else {
97
+ const patternAsStr = `[${otherChars.map(escapeRegexp).join('')}]`;
98
+ const pattern = RegExp(patternAsStr, 'g');
99
+ replacedSource = source.replace(pattern, ' ');
100
+ }
101
+ let col = 0;
102
+ let line = 0;
103
+ let lastCol = 0;
104
+ let lastLine = 0;
105
+ let startPosition;
106
+ for (const currentChar of replacedSource) {
107
+ if (currentChar === '\n') {
108
+ col = 0;
109
+ line++;
110
+ continue;
111
+ }
112
+ col++;
113
+ if (currentChar !== specialChar)
114
+ continue;
115
+ if (!startPosition) {
116
+ startPosition = {
117
+ character: col - 1,
118
+ line: line - 1,
119
+ };
120
+ }
121
+ lastCol = col;
122
+ lastLine = line - 1;
123
+ }
124
+ const endPosition = {
125
+ character: lastCol,
126
+ line: lastLine,
127
+ };
128
+ const newSource = replacedSource.replace(RegExp(escapeRegexp(specialChar), 'g'), '');
129
+ return {
130
+ failure: {
131
+ endPosition,
132
+ message: '',
133
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
134
+ startPosition: startPosition,
135
+ },
136
+ source: newSource,
137
+ };
138
+ }
@@ -77,7 +77,7 @@ export declare const angularLifecycleInterfaceKeys: readonly ("AfterContentCheck
77
77
  export declare const angularLifecycleMethodKeys: readonly ("ngAfterContentChecked" | "ngAfterContentInit" | "ngAfterViewChecked" | "ngAfterViewInit" | "ngDoBootstrap" | "ngDoCheck" | "ngOnChanges" | "ngOnDestroy" | "ngOnInit")[];
78
78
  /**
79
79
  * See lifecycle event sequence:
80
- * https://angular.dev/guide/components/lifecycle
80
+ * https://angular.io/guide/lifecycle-hooks#lifecycle-event-sequence
81
81
  */
82
82
  export declare const angularLifecycleMethodsOrdered: AngularLifecycleMethods[];
83
83
  export declare const ANGULAR_CLASS_DECORATOR_LIFECYCLE_METHOD_MAPPER: ReadonlyMap<AngularClassDecoratorKeys, ReadonlySet<AngularLifecycleMethodKeys>>;
@@ -72,7 +72,7 @@ exports.angularLifecycleInterfaceKeys = (0, utils_2.objectKeys)(AngularLifecycle
72
72
  exports.angularLifecycleMethodKeys = (0, utils_2.objectKeys)(AngularLifecycleMethods);
73
73
  /**
74
74
  * See lifecycle event sequence:
75
- * https://angular.dev/guide/components/lifecycle
75
+ * https://angular.io/guide/lifecycle-hooks#lifecycle-event-sequence
76
76
  */
77
77
  exports.angularLifecycleMethodsOrdered = [
78
78
  AngularLifecycleMethods.ngOnChanges,
@@ -1 +1 @@
1
- {"version":3,"file":"parser-services.d.ts","sourceRoot":"","sources":["../../src/eslint-plugin-template/parser-services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACf,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEnE,MAAM,WAAW,sBAAsB;IACrC,0BAA0B,EAAE,CAC1B,UAAU,EAAE,eAAe,KACxB,QAAQ,CAAC,cAAc,CAAC;IAC7B,6BAA6B,EAAE,CAC7B,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,EACnE,IAAI,EAAE,cAAc,KACjB,QAAQ,CAAC,cAAc,CAAC;CAC9B;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,GAClE,sBAAsB,CAGxB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,GAClE,IAAI,CAgBN"}
1
+ {"version":3,"file":"parser-services.d.ts","sourceRoot":"","sources":["../../src/eslint-plugin-template/parser-services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACf,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEnE,MAAM,WAAW,sBAAsB;IACrC,0BAA0B,EAAE,CAC1B,UAAU,EAAE,eAAe,KACxB,QAAQ,CAAC,cAAc,CAAC;IAC7B,6BAA6B,EAAE,CAC7B,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,EACnE,IAAI,EAAE,cAAc,KACjB,QAAQ,CAAC,cAAc,CAAC;CAC9B;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,GAClE,sBAAsB,CAGxB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,GAClE,IAAI,CAeN"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ensureTemplateParser = exports.getTemplateParserServices = void 0;
4
4
  function getTemplateParserServices(context) {
5
5
  ensureTemplateParser(context);
6
- return context.sourceCode.parserServices;
6
+ return context.parserServices;
7
7
  }
8
8
  exports.getTemplateParserServices = getTemplateParserServices;
9
9
  /**
@@ -11,10 +11,10 @@ exports.getTemplateParserServices = getTemplateParserServices;
11
11
  * If @angular-eslint/template-parser is not the configured parser when the function is invoked it will throw
12
12
  */
13
13
  function ensureTemplateParser(context) {
14
- const parserServices = context.sourceCode
15
- .parserServices;
16
- if (!parserServices?.convertNodeSourceSpanToLoc ||
17
- !parserServices?.convertElementSourceSpanToLoc) {
14
+ if (!context.parserServices
15
+ ?.convertNodeSourceSpanToLoc ||
16
+ !context.parserServices
17
+ ?.convertElementSourceSpanToLoc) {
18
18
  /**
19
19
  * The user needs to have configured "parser" in their eslint config and set it
20
20
  * to @angular-eslint/template-parser
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './convert-annotated-source-to-failure-case';
2
+ export * from './rules-tester';
1
3
  export { toHumanReadableText, arrayify, isNotNullOrUndefined, toPattern, kebabToCamelCase, withoutBracketsAndWhitespaces, capitalize, } from './utils';
2
4
  export { getAriaAttributeKeys } from './eslint-plugin/get-aria-attribute-keys';
3
5
  export { getNativeEventNames } from './eslint-plugin/get-native-event-names';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,oBAAoB,EACpB,SAAS,EACT,gBAAgB,EAChB,6BAA6B,EAC7B,UAAU,GACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAE7E,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,SAAS,MAAM,4BAA4B,CAAC;AACxD,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AACvD,OAAO,KAAK,aAAa,MAAM,gCAAgC,CAAC;AAEhE,YAAY,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,0CAA0C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4CAA4C,CAAC;AAC3D,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,oBAAoB,EACpB,SAAS,EACT,gBAAgB,EAChB,6BAA6B,EAC7B,UAAU,GACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAE7E,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,SAAS,MAAM,4BAA4B,CAAC;AACxD,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AACvD,OAAO,KAAK,aAAa,MAAM,gCAAgC,CAAC;AAEhE,YAAY,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,0CAA0C,CAAC"}
package/dist/index.js CHANGED
@@ -15,6 +15,9 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
18
21
  var __importStar = (this && this.__importStar) || function (mod) {
19
22
  if (mod && mod.__esModule) return mod;
20
23
  var result = {};
@@ -24,6 +27,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
27
  };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.getTemplateParserServices = exports.ensureTemplateParser = exports.SelectorUtils = exports.Selectors = exports.RuleFixes = exports.ASTUtils = exports.getNativeEventNames = exports.getAriaAttributeKeys = exports.capitalize = exports.withoutBracketsAndWhitespaces = exports.kebabToCamelCase = exports.toPattern = exports.isNotNullOrUndefined = exports.arrayify = exports.toHumanReadableText = void 0;
30
+ __exportStar(require("./convert-annotated-source-to-failure-case"), exports);
31
+ __exportStar(require("./rules-tester"), exports);
27
32
  var utils_1 = require("./utils");
28
33
  Object.defineProperty(exports, "toHumanReadableText", { enumerable: true, get: function () { return utils_1.toHumanReadableText; } });
29
34
  Object.defineProperty(exports, "arrayify", { enumerable: true, get: function () { return utils_1.arrayify; } });
@@ -0,0 +1,12 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+ declare const VALID_PARSERS: readonly ["@angular-eslint/template-parser", "@typescript-eslint/parser"];
3
+ type RuleTesterConfig = Omit<TSESLint.RuleTesterConfig, 'parser'> & {
4
+ parser: (typeof VALID_PARSERS)[number];
5
+ };
6
+ export declare class RuleTester extends TSESLint.RuleTester {
7
+ private filename?;
8
+ constructor(options: RuleTesterConfig);
9
+ run<TMessageIds extends string, TOptions extends readonly unknown[]>(name: string, rule: TSESLint.RuleModule<TMessageIds, TOptions>, { valid, invalid }: TSESLint.RunTests<TMessageIds, TOptions>): void;
10
+ }
11
+ export {};
12
+ //# sourceMappingURL=rules-tester.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules-tester.d.ts","sourceRoot":"","sources":["../src/rules-tester.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGpD,QAAA,MAAM,aAAa,2EAGT,CAAC;AAEX,KAAK,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,GAAG;IAClE,MAAM,EAAE,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAYF,qBAAa,UAAW,SAAQ,QAAQ,CAAC,UAAU;IACjD,OAAO,CAAC,QAAQ,CAAC,CAAS;gBAKd,OAAO,EAAE,gBAAgB;IA8B5B,GAAG,CAAC,WAAW,SAAS,MAAM,EAAE,QAAQ,SAAS,SAAS,OAAO,EAAE,EAC1E,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,QAAQ,CAAC,EAChD,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,GAC3D,IAAI;CA0BR"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.RuleTester = void 0;
27
+ const utils_1 = require("@typescript-eslint/utils");
28
+ const path = __importStar(require("path"));
29
+ const VALID_PARSERS = [
30
+ '@angular-eslint/template-parser',
31
+ '@typescript-eslint/parser',
32
+ ];
33
+ function getFixturesRootDir() {
34
+ return path.join(process.cwd(), 'tests/fixtures/');
35
+ }
36
+ function isValidParser(parser) {
37
+ return VALID_PARSERS.includes(parser);
38
+ }
39
+ class RuleTester extends utils_1.TSESLint.RuleTester {
40
+ filename;
41
+ // as of eslint 6 you have to provide an absolute path to the parser
42
+ // but that's not as clean to type, this saves us trying to manually enforce
43
+ // that contributors require.resolve everything
44
+ constructor(options) {
45
+ super({
46
+ ...options,
47
+ parser: require.resolve(options.parser),
48
+ });
49
+ if (options.parserOptions?.project) {
50
+ this.filename = path.join(options.parserOptions?.tsconfigRootDir ?? getFixturesRootDir(), 'file.ts');
51
+ }
52
+ // make sure that the parser doesn't hold onto file handles between tests
53
+ // on linux (i.e. our CI env), there can be very a limited number of watch handles available
54
+ afterAll(() => {
55
+ try {
56
+ // instead of creating a hard dependency, just use a soft require
57
+ // a bit weird, but if they're using this tooling, it'll be installed
58
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
59
+ require(options.parser).clearCaches();
60
+ }
61
+ catch {
62
+ // ignored
63
+ }
64
+ });
65
+ }
66
+ // as of eslint 6 you have to provide an absolute path to the parser
67
+ // If you don't do that at the test level, the test will fail somewhat cryptically...
68
+ // This is a lot more explicit
69
+ run(name, rule, { valid, invalid }) {
70
+ const errorMessage = `Do not set the parser at the test level unless you want to use a parser other than ${VALID_PARSERS.join(', ')}`;
71
+ const parsedTests = {
72
+ valid: valid.map((test) => {
73
+ if (typeof test !== 'string' && isValidParser(test.parser)) {
74
+ throw Error(errorMessage);
75
+ }
76
+ return typeof test === 'string'
77
+ ? { code: test, filename: this.filename }
78
+ : { ...test, filename: test.filename ?? this.filename };
79
+ }),
80
+ invalid: invalid.map((test) => {
81
+ if (isValidParser(test.parser)) {
82
+ throw Error(errorMessage);
83
+ }
84
+ return {
85
+ ...test,
86
+ filename: test.filename ?? this.filename,
87
+ };
88
+ }),
89
+ };
90
+ super.run(name, rule, parsedTests);
91
+ }
92
+ }
93
+ exports.RuleTester = RuleTester;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/utils",
3
- "version": "17.5.3-alpha.1",
3
+ "version": "17.5.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,12 +17,12 @@
17
17
  "LICENSE"
18
18
  ],
19
19
  "peerDependencies": {
20
- "eslint": "^8.57.0 || ^9.0.0",
20
+ "eslint": "^7.20.0 || ^8.0.0",
21
21
  "typescript": "*"
22
22
  },
23
23
  "dependencies": {
24
- "@angular-eslint/bundled-angular-compiler": "17.5.3-alpha.1",
25
- "@typescript-eslint/utils": "8.0.0-alpha.20"
24
+ "@angular-eslint/bundled-angular-compiler": "17.5.3",
25
+ "@typescript-eslint/utils": "7.11.0"
26
26
  },
27
27
  "gitHead": "e2006e5e9c99e5a943d1a999e0efa5247d29ec24"
28
28
  }