@typescript-eslint/rule-tester 6.0.0-alpha.158

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.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/_ts4.2/dist/RuleTester.d.ts +46 -0
  4. package/_ts4.2/dist/TestFramework.d.ts +66 -0
  5. package/_ts4.2/dist/index.d.ts +5 -0
  6. package/_ts4.2/dist/noFormat.d.ts +6 -0
  7. package/_ts4.2/dist/types/DependencyConstraint.d.ts +14 -0
  8. package/_ts4.2/dist/types/InvalidTestCase.d.ts +68 -0
  9. package/_ts4.2/dist/types/RuleTesterConfig.d.ts +26 -0
  10. package/_ts4.2/dist/types/ValidTestCase.d.ts +53 -0
  11. package/_ts4.2/dist/types/index.d.ts +19 -0
  12. package/_ts4.2/dist/utils/SourceCodeFixer.d.ts +16 -0
  13. package/_ts4.2/dist/utils/ajv.d.ts +3 -0
  14. package/_ts4.2/dist/utils/cloneDeeplyExcludesParent.d.ts +6 -0
  15. package/_ts4.2/dist/utils/config-schema.d.ts +3 -0
  16. package/_ts4.2/dist/utils/config-validator.d.ts +12 -0
  17. package/_ts4.2/dist/utils/dependencyConstraints.d.ts +3 -0
  18. package/_ts4.2/dist/utils/deprecation-warnings.d.ts +13 -0
  19. package/_ts4.2/dist/utils/freezeDeeply.d.ts +5 -0
  20. package/_ts4.2/dist/utils/getRuleOptionsSchema.d.ts +9 -0
  21. package/_ts4.2/dist/utils/hasOwnProperty.d.ts +4 -0
  22. package/_ts4.2/dist/utils/interpolate.d.ts +3 -0
  23. package/_ts4.2/dist/utils/isReadonlyArray.d.ts +2 -0
  24. package/_ts4.2/dist/utils/validationHelpers.d.ts +43 -0
  25. package/dist/RuleTester.d.ts +46 -0
  26. package/dist/RuleTester.d.ts.map +1 -0
  27. package/dist/RuleTester.js +658 -0
  28. package/dist/RuleTester.js.map +1 -0
  29. package/dist/TestFramework.d.ts +66 -0
  30. package/dist/TestFramework.d.ts.map +1 -0
  31. package/dist/TestFramework.js +148 -0
  32. package/dist/TestFramework.js.map +1 -0
  33. package/dist/index.d.ts +5 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +8 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/noFormat.d.ts +6 -0
  38. package/dist/noFormat.d.ts.map +1 -0
  39. package/dist/noFormat.js +12 -0
  40. package/dist/noFormat.js.map +1 -0
  41. package/dist/types/DependencyConstraint.d.ts +14 -0
  42. package/dist/types/DependencyConstraint.d.ts.map +1 -0
  43. package/dist/types/DependencyConstraint.js +3 -0
  44. package/dist/types/DependencyConstraint.js.map +1 -0
  45. package/dist/types/InvalidTestCase.d.ts +68 -0
  46. package/dist/types/InvalidTestCase.d.ts.map +1 -0
  47. package/dist/types/InvalidTestCase.js +3 -0
  48. package/dist/types/InvalidTestCase.js.map +1 -0
  49. package/dist/types/RuleTesterConfig.d.ts +26 -0
  50. package/dist/types/RuleTesterConfig.d.ts.map +1 -0
  51. package/dist/types/RuleTesterConfig.js +3 -0
  52. package/dist/types/RuleTesterConfig.js.map +1 -0
  53. package/dist/types/ValidTestCase.d.ts +53 -0
  54. package/dist/types/ValidTestCase.d.ts.map +1 -0
  55. package/dist/types/ValidTestCase.js +3 -0
  56. package/dist/types/ValidTestCase.js.map +1 -0
  57. package/dist/types/index.d.ts +19 -0
  58. package/dist/types/index.d.ts.map +1 -0
  59. package/dist/types/index.js +3 -0
  60. package/dist/types/index.js.map +1 -0
  61. package/dist/utils/SourceCodeFixer.d.ts +16 -0
  62. package/dist/utils/SourceCodeFixer.d.ts.map +1 -0
  63. package/dist/utils/SourceCodeFixer.js +93 -0
  64. package/dist/utils/SourceCodeFixer.js.map +1 -0
  65. package/dist/utils/ajv.d.ts +3 -0
  66. package/dist/utils/ajv.d.ts.map +1 -0
  67. package/dist/utils/ajv.js +26 -0
  68. package/dist/utils/ajv.js.map +1 -0
  69. package/dist/utils/cloneDeeplyExcludesParent.d.ts +6 -0
  70. package/dist/utils/cloneDeeplyExcludesParent.d.ts.map +1 -0
  71. package/dist/utils/cloneDeeplyExcludesParent.js +24 -0
  72. package/dist/utils/cloneDeeplyExcludesParent.js.map +1 -0
  73. package/dist/utils/config-schema.d.ts +3 -0
  74. package/dist/utils/config-schema.d.ts.map +1 -0
  75. package/dist/utils/config-schema.js +87 -0
  76. package/dist/utils/config-schema.js.map +1 -0
  77. package/dist/utils/config-validator.d.ts +12 -0
  78. package/dist/utils/config-validator.d.ts.map +1 -0
  79. package/dist/utils/config-validator.js +208 -0
  80. package/dist/utils/config-validator.js.map +1 -0
  81. package/dist/utils/dependencyConstraints.d.ts +3 -0
  82. package/dist/utils/dependencyConstraints.d.ts.map +1 -0
  83. package/dist/utils/dependencyConstraints.js +53 -0
  84. package/dist/utils/dependencyConstraints.js.map +1 -0
  85. package/dist/utils/deprecation-warnings.d.ts +13 -0
  86. package/dist/utils/deprecation-warnings.d.ts.map +1 -0
  87. package/dist/utils/deprecation-warnings.js +32 -0
  88. package/dist/utils/deprecation-warnings.js.map +1 -0
  89. package/dist/utils/freezeDeeply.d.ts +5 -0
  90. package/dist/utils/freezeDeeply.d.ts.map +1 -0
  91. package/dist/utils/freezeDeeply.js +23 -0
  92. package/dist/utils/freezeDeeply.js.map +1 -0
  93. package/dist/utils/getRuleOptionsSchema.d.ts +9 -0
  94. package/dist/utils/getRuleOptionsSchema.d.ts.map +1 -0
  95. package/dist/utils/getRuleOptionsSchema.js +33 -0
  96. package/dist/utils/getRuleOptionsSchema.js.map +1 -0
  97. package/dist/utils/hasOwnProperty.d.ts +2 -0
  98. package/dist/utils/hasOwnProperty.d.ts.map +1 -0
  99. package/dist/utils/hasOwnProperty.js +6 -0
  100. package/dist/utils/hasOwnProperty.js.map +1 -0
  101. package/dist/utils/interpolate.d.ts +3 -0
  102. package/dist/utils/interpolate.d.ts.map +1 -0
  103. package/dist/utils/interpolate.js +20 -0
  104. package/dist/utils/interpolate.js.map +1 -0
  105. package/dist/utils/isReadonlyArray.d.ts +2 -0
  106. package/dist/utils/isReadonlyArray.d.ts.map +1 -0
  107. package/dist/utils/isReadonlyArray.js +9 -0
  108. package/dist/utils/isReadonlyArray.js.map +1 -0
  109. package/dist/utils/validationHelpers.d.ts +29 -0
  110. package/dist/utils/validationHelpers.d.ts.map +1 -0
  111. package/dist/utils/validationHelpers.js +158 -0
  112. package/dist/utils/validationHelpers.js.map +1 -0
  113. package/package.json +83 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"freezeDeeply.d.ts","sourceRoot":"","sources":["../../src/utils/freezeDeeply.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,CAa7C"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.freezeDeeply = void 0;
4
+ /**
5
+ * Freezes a given value deeply.
6
+ */
7
+ function freezeDeeply(x) {
8
+ if (typeof x === 'object' && x != null) {
9
+ if (Array.isArray(x)) {
10
+ x.forEach(freezeDeeply);
11
+ }
12
+ else {
13
+ for (const key in x) {
14
+ if (key !== 'parent' && Object.prototype.hasOwnProperty.call(x, key)) {
15
+ freezeDeeply(x[key]);
16
+ }
17
+ }
18
+ }
19
+ Object.freeze(x);
20
+ }
21
+ }
22
+ exports.freezeDeeply = freezeDeeply;
23
+ //# sourceMappingURL=freezeDeeply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"freezeDeeply.js","sourceRoot":"","sources":["../../src/utils/freezeDeeply.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,SAAgB,YAAY,CAAC,CAAU;IACrC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,IAAI,IAAI,EAAE;QACtC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACpB,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;SACzB;aAAM;YACL,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE;gBACnB,IAAI,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;oBACpE,YAAY,CAAE,CAA6B,CAAC,GAAG,CAAC,CAAC,CAAC;iBACnD;aACF;SACF;QACD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KAClB;AACH,CAAC;AAbD,oCAaC"}
@@ -0,0 +1,9 @@
1
+ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
2
+ import type { AnyRuleModule } from '@typescript-eslint/utils/ts-eslint';
3
+ /**
4
+ * Gets a complete options schema for a rule.
5
+ * @param rule A new-style rule object
6
+ * @returns JSON Schema for the rule's options.
7
+ */
8
+ export declare function getRuleOptionsSchema(rule: AnyRuleModule): JSONSchema4 | null;
9
+ //# sourceMappingURL=getRuleOptionsSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRuleOptionsSchema.d.ts","sourceRoot":"","sources":["../../src/utils/getRuleOptionsSchema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAIxE;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,aAAa,GAAG,WAAW,GAAG,IAAI,CAsB5E"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // Forked from https://github.com/eslint/eslint/blob/ad9dd6a933fd098a0d99c6a9aa059850535c23ee/lib/shared/config-validator.js#LL50-L82C2
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getRuleOptionsSchema = void 0;
5
+ const isReadonlyArray_1 = require("./isReadonlyArray");
6
+ /**
7
+ * Gets a complete options schema for a rule.
8
+ * @param rule A new-style rule object
9
+ * @returns JSON Schema for the rule's options.
10
+ */
11
+ function getRuleOptionsSchema(rule) {
12
+ const schema = rule.meta?.schema;
13
+ // Given a tuple of schemas, insert warning level at the beginning
14
+ if ((0, isReadonlyArray_1.isReadonlyArray)(schema)) {
15
+ if (schema.length) {
16
+ return {
17
+ type: 'array',
18
+ items: schema,
19
+ minItems: 0,
20
+ maxItems: schema.length,
21
+ };
22
+ }
23
+ return {
24
+ type: 'array',
25
+ minItems: 0,
26
+ maxItems: 0,
27
+ };
28
+ }
29
+ // Given a full schema, leave it alone
30
+ return schema || null;
31
+ }
32
+ exports.getRuleOptionsSchema = getRuleOptionsSchema;
33
+ //# sourceMappingURL=getRuleOptionsSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRuleOptionsSchema.js","sourceRoot":"","sources":["../../src/utils/getRuleOptionsSchema.ts"],"names":[],"mappings":";AAAA,uIAAuI;;;AAKvI,uDAAoD;AAEpD;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,IAAmB;IACtD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;IAEjC,kEAAkE;IAClE,IAAI,IAAA,iCAAe,EAAC,MAAM,CAAC,EAAE;QAC3B,IAAI,MAAM,CAAC,MAAM,EAAE;YACjB,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,MAAuB;gBAC9B,QAAQ,EAAE,CAAC;gBACX,QAAQ,EAAE,MAAM,CAAC,MAAM;aACxB,CAAC;SACH;QACD,OAAO;YACL,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,CAAC;SACZ,CAAC;KACH;IAED,sCAAsC;IACtC,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC;AAtBD,oDAsBC"}
@@ -0,0 +1,2 @@
1
+ export declare const hasOwnProperty: <TObj extends object, TK extends keyof TObj>(obj: TObj, key: TK) => obj is TObj & { [key in TK]-?: TObj[key]; };
2
+ //# sourceMappingURL=hasOwnProperty.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasOwnProperty.d.ts","sourceRoot":"","sources":["../../src/utils/hasOwnProperty.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,iHAMoB,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasOwnProperty = void 0;
4
+ // typed so that TS can remove optionality
5
+ exports.hasOwnProperty = Function.call.bind(Object.hasOwnProperty);
6
+ //# sourceMappingURL=hasOwnProperty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasOwnProperty.js","sourceRoot":"","sources":["../../src/utils/hasOwnProperty.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC7B,QAAA,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAMvB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ReportDescriptorMessageData } from '@typescript-eslint/utils/ts-eslint';
2
+ export declare function interpolate(text: string, data: ReportDescriptorMessageData): string;
3
+ //# sourceMappingURL=interpolate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../src/utils/interpolate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEtF,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,2BAA2B,GAChC,MAAM,CAmBR"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ // Forked from https://github.com/eslint/eslint/blob/ad9dd6a933fd098a0d99c6a9aa059850535c23ee/lib/linter/interpolate.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.interpolate = void 0;
5
+ function interpolate(text, data) {
6
+ if (!data) {
7
+ return text;
8
+ }
9
+ // Substitution content for any {{ }} markers.
10
+ return text.replace(/\{\{([^{}]+?)\}\}/gu, (fullMatch, termWithWhitespace) => {
11
+ const term = termWithWhitespace.trim();
12
+ if (term in data) {
13
+ return String(data[term]);
14
+ }
15
+ // Preserve old behavior: If parameter name not provided, don't replace it.
16
+ return fullMatch;
17
+ });
18
+ }
19
+ exports.interpolate = interpolate;
20
+ //# sourceMappingURL=interpolate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpolate.js","sourceRoot":"","sources":["../../src/utils/interpolate.ts"],"names":[],"mappings":";AAAA,uHAAuH;;;AAIvH,SAAgB,WAAW,CACzB,IAAY,EACZ,IAAiC;IAEjC,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,IAAI,CAAC;KACb;IAED,8CAA8C;IAC9C,OAAO,IAAI,CAAC,OAAO,CACjB,qBAAqB,EACrB,CAAC,SAAS,EAAE,kBAA0B,EAAE,EAAE;QACxC,MAAM,IAAI,GAAG,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAEvC,IAAI,IAAI,IAAI,IAAI,EAAE;YAChB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SAC3B;QAED,2EAA2E;QAC3E,OAAO,SAAS,CAAC;IACnB,CAAC,CACF,CAAC;AACJ,CAAC;AAtBD,kCAsBC"}
@@ -0,0 +1,2 @@
1
+ export declare function isReadonlyArray(arg: unknown): arg is readonly unknown[];
2
+ //# sourceMappingURL=isReadonlyArray.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isReadonlyArray.d.ts","sourceRoot":"","sources":["../../src/utils/isReadonlyArray.ts"],"names":[],"mappings":"AACA,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,OAAO,EAAE,CAEvE"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isReadonlyArray = void 0;
4
+ // working around https://github.com/microsoft/TypeScript/issues/17002
5
+ function isReadonlyArray(arg) {
6
+ return Array.isArray(arg);
7
+ }
8
+ exports.isReadonlyArray = isReadonlyArray;
9
+ //# sourceMappingURL=isReadonlyArray.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isReadonlyArray.js","sourceRoot":"","sources":["../../src/utils/isReadonlyArray.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACtE,SAAgB,eAAe,CAAC,GAAY;IAC1C,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAFD,0CAEC"}
@@ -0,0 +1,29 @@
1
+ import type { Linter } from '@typescript-eslint/utils/ts-eslint';
2
+ export declare const RULE_TESTER_PARAMETERS: readonly ["code", "defaultFilenames", "dependencyConstraints", "errors", "filename", "name", "only", "options", "output", "skip"];
3
+ export declare const ERROR_OBJECT_PARAMETERS: ReadonlySet<string>;
4
+ export declare const FRIENDLY_ERROR_OBJECT_PARAMETER_LIST: string;
5
+ export declare const SUGGESTION_OBJECT_PARAMETERS: ReadonlySet<string>;
6
+ export declare const FRIENDLY_SUGGESTION_OBJECT_PARAMETER_LIST: string;
7
+ /**
8
+ * Replace control characters by `\u00xx` form.
9
+ */
10
+ export declare function sanitize(text: string): string;
11
+ /**
12
+ * Wraps the given parser in order to intercept and modify return values from the `parse` and `parseForESLint` methods, for test purposes.
13
+ * In particular, to modify ast nodes, tokens and comments to throw on access to their `start` and `end` properties.
14
+ */
15
+ export declare function wrapParser(parser: Linter.ParserModule): Linter.ParserModule;
16
+ /**
17
+ * Function to replace `SourceCode.prototype.getComments`.
18
+ */
19
+ export declare function getCommentsDeprecation(): never;
20
+ /**
21
+ * Emit a deprecation warning if function-style format is being used.
22
+ */
23
+ export declare function emitLegacyRuleAPIWarning(ruleName: string): void;
24
+ /**
25
+ * Emit a deprecation warning if rule has options but is missing the "meta.schema" property
26
+ */
27
+ export declare function emitMissingSchemaWarning(ruleName: string): void;
28
+ export declare const REQUIRED_SCENARIOS: readonly ["valid", "invalid"];
29
+ //# sourceMappingURL=validationHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/validationHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,oCAAoC,CAAC;AAM7E,eAAO,MAAM,sBAAsB,mIAWzB,CAAC;AAKX,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAUtD,CAAC;AACH,eAAO,MAAM,oCAAoC,QAIjC,CAAC;AAKjB,eAAO,MAAM,4BAA4B,EAAE,WAAW,CAAC,MAAM,CAK3D,CAAC;AACH,eAAO,MAAM,yCAAyC,QAItC,CAAC;AAEjB;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS7C;AAKD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAiE3E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,KAAK,CAI9C;AAGD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAQ/D;AAGD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAQ/D;AAED,eAAO,MAAM,kBAAkB,+BAAgC,CAAC"}
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REQUIRED_SCENARIOS = exports.emitMissingSchemaWarning = exports.emitLegacyRuleAPIWarning = exports.getCommentsDeprecation = exports.wrapParser = exports.sanitize = exports.FRIENDLY_SUGGESTION_OBJECT_PARAMETER_LIST = exports.SUGGESTION_OBJECT_PARAMETERS = exports.FRIENDLY_ERROR_OBJECT_PARAMETER_LIST = exports.ERROR_OBJECT_PARAMETERS = exports.RULE_TESTER_PARAMETERS = void 0;
4
+ const typescript_estree_1 = require("@typescript-eslint/typescript-estree");
5
+ /*
6
+ * List every parameters possible on a test case that are not related to eslint
7
+ * configuration
8
+ */
9
+ exports.RULE_TESTER_PARAMETERS = [
10
+ 'code',
11
+ 'defaultFilenames',
12
+ 'dependencyConstraints',
13
+ 'errors',
14
+ 'filename',
15
+ 'name',
16
+ 'only',
17
+ 'options',
18
+ 'output',
19
+ 'skip',
20
+ ];
21
+ /*
22
+ * All allowed property names in error objects.
23
+ */
24
+ exports.ERROR_OBJECT_PARAMETERS = new Set([
25
+ 'column',
26
+ 'data',
27
+ 'endColumn',
28
+ 'endLine',
29
+ 'line',
30
+ 'message',
31
+ 'messageId',
32
+ 'suggestions',
33
+ 'type',
34
+ ]);
35
+ exports.FRIENDLY_ERROR_OBJECT_PARAMETER_LIST = `[${[
36
+ ...exports.ERROR_OBJECT_PARAMETERS,
37
+ ]
38
+ .map(key => `'${key}'`)
39
+ .join(', ')}]`;
40
+ /*
41
+ * All allowed property names in suggestion objects.
42
+ */
43
+ exports.SUGGESTION_OBJECT_PARAMETERS = new Set([
44
+ 'data',
45
+ 'desc',
46
+ 'messageId',
47
+ 'output',
48
+ ]);
49
+ exports.FRIENDLY_SUGGESTION_OBJECT_PARAMETER_LIST = `[${[
50
+ ...exports.SUGGESTION_OBJECT_PARAMETERS,
51
+ ]
52
+ .map(key => `'${key}'`)
53
+ .join(', ')}]`;
54
+ /**
55
+ * Replace control characters by `\u00xx` form.
56
+ */
57
+ function sanitize(text) {
58
+ if (typeof text !== 'string') {
59
+ return '';
60
+ }
61
+ return text.replace(
62
+ // eslint-disable-next-line no-control-regex
63
+ /[\u0000-\u0009\u000b-\u001a]/gu, c => `\\u${c.codePointAt(0).toString(16).padStart(4, '0')}`);
64
+ }
65
+ exports.sanitize = sanitize;
66
+ // this symbol is used internally by ESLint to unwrap the wrapped parser
67
+ // https://github.com/eslint/eslint/blob/129e252132c7c476d7de17f40b54a333ddb2e6bb/lib/linter/linter.js#L139-L146
68
+ const parserSymbol = Symbol.for('eslint.RuleTester.parser');
69
+ /**
70
+ * Wraps the given parser in order to intercept and modify return values from the `parse` and `parseForESLint` methods, for test purposes.
71
+ * In particular, to modify ast nodes, tokens and comments to throw on access to their `start` and `end` properties.
72
+ */
73
+ function wrapParser(parser) {
74
+ /**
75
+ * Define `start`/`end` properties of all nodes of the given AST as throwing error.
76
+ */
77
+ function defineStartEndAsErrorInTree(ast, visitorKeys) {
78
+ /**
79
+ * Define `start`/`end` properties as throwing error.
80
+ */
81
+ function defineStartEndAsError(objName, node) {
82
+ Object.defineProperties(node, {
83
+ start: {
84
+ get() {
85
+ throw new Error(`Use ${objName}.range[0] instead of ${objName}.start`);
86
+ },
87
+ configurable: true,
88
+ enumerable: false,
89
+ },
90
+ end: {
91
+ get() {
92
+ throw new Error(`Use ${objName}.range[1] instead of ${objName}.end`);
93
+ },
94
+ configurable: true,
95
+ enumerable: false,
96
+ },
97
+ });
98
+ }
99
+ (0, typescript_estree_1.simpleTraverse)(ast, {
100
+ visitorKeys: visitorKeys,
101
+ enter: node => defineStartEndAsError('node', node),
102
+ });
103
+ ast.tokens?.forEach(token => defineStartEndAsError('token', token));
104
+ ast.comments?.forEach(comment => defineStartEndAsError('token', comment));
105
+ }
106
+ if ('parseForESLint' in parser) {
107
+ return {
108
+ // @ts-expect-error -- see above
109
+ [parserSymbol]: parser,
110
+ parseForESLint(...args) {
111
+ const ret = parser.parseForESLint(...args);
112
+ defineStartEndAsErrorInTree(ret.ast, ret.visitorKeys);
113
+ return ret;
114
+ },
115
+ };
116
+ }
117
+ return {
118
+ // @ts-expect-error -- see above
119
+ [parserSymbol]: parser,
120
+ parse(...args) {
121
+ const ast = parser.parse(...args);
122
+ defineStartEndAsErrorInTree(ast);
123
+ return ast;
124
+ },
125
+ };
126
+ }
127
+ exports.wrapParser = wrapParser;
128
+ /**
129
+ * Function to replace `SourceCode.prototype.getComments`.
130
+ */
131
+ function getCommentsDeprecation() {
132
+ throw new Error('`SourceCode#getComments()` is deprecated and will be removed in a future major version. Use `getCommentsBefore()`, `getCommentsAfter()`, and `getCommentsInside()` instead.');
133
+ }
134
+ exports.getCommentsDeprecation = getCommentsDeprecation;
135
+ const EMIT_LEGACY_RULE_API_WARNING = {};
136
+ /**
137
+ * Emit a deprecation warning if function-style format is being used.
138
+ */
139
+ function emitLegacyRuleAPIWarning(ruleName) {
140
+ if (!EMIT_LEGACY_RULE_API_WARNING[`warned-${ruleName}`]) {
141
+ EMIT_LEGACY_RULE_API_WARNING[`warned-${ruleName}`] = true;
142
+ process.emitWarning(`"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/latest/extend/custom-rules`, 'DeprecationWarning');
143
+ }
144
+ }
145
+ exports.emitLegacyRuleAPIWarning = emitLegacyRuleAPIWarning;
146
+ const EMIT_MISSING_SCHEMA_WARNING = {};
147
+ /**
148
+ * Emit a deprecation warning if rule has options but is missing the "meta.schema" property
149
+ */
150
+ function emitMissingSchemaWarning(ruleName) {
151
+ if (!EMIT_MISSING_SCHEMA_WARNING[`warned-${ruleName}`]) {
152
+ EMIT_MISSING_SCHEMA_WARNING[`warned-${ruleName}`] = true;
153
+ process.emitWarning(`"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/latest/extend/custom-rules#options-schemas`, 'DeprecationWarning');
154
+ }
155
+ }
156
+ exports.emitMissingSchemaWarning = emitMissingSchemaWarning;
157
+ exports.REQUIRED_SCENARIOS = ['valid', 'invalid'];
158
+ //# sourceMappingURL=validationHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationHelpers.js","sourceRoot":"","sources":["../../src/utils/validationHelpers.ts"],"names":[],"mappings":";;;AAAA,4EAAsE;AAItE;;;GAGG;AACU,QAAA,sBAAsB,GAAG;IACpC,MAAM;IACN,kBAAkB;IAClB,uBAAuB;IACvB,QAAQ;IACR,UAAU;IACV,MAAM;IACN,MAAM;IACN,SAAS;IACT,QAAQ;IACR,MAAM;CACE,CAAC;AAEX;;GAEG;AACU,QAAA,uBAAuB,GAAwB,IAAI,GAAG,CAAC;IAClE,Q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MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAElC,2BAA2B,CAAC,GAAG,CAAC,CAAC;YACjC,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC;AAjED,gCAiEC;AAED;;GAEG;AACH,SAAgB,sBAAsB;IACpC,MAAM,IAAI,KAAK,CACb,6KAA6K,CAC9K,CAAC;AACJ,CAAC;AAJD,wDAIC;AAED,MAAM,4BAA4B,GAA4B,EAAE,CAAC;AACjE;;GAEG;AACH,SAAgB,wBAAwB,CAAC,QAAgB;IACvD,IAAI,CAAC,4BAA4B,CAAC,UAAU,QAAQ,EAAE,CAAC,EAAE;QACvD,4BAA4B,CAAC,UAAU,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC;QAC1D,OAAO,CAAC,WAAW,CACjB,IAAI,QAAQ,6KAA6K,EACzL,oBAAoB,CACrB,CAAC;KACH;AACH,CAAC;AARD,4DAQC;AAED,MAAM,2BAA2B,GAA4B,EAAE,CAAC;AAChE;;GAEG;AACH,SAAgB,wBAAwB,CAAC,QAAgB;IACvD,IAAI,CAAC,2BAA2B,CAAC,UAAU,QAAQ,EAAE,CAAC,EAAE;QACtD,2BAA2B,CAAC,UAAU,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC;QACzD,OAAO,CAAC,WAAW,CACjB,IAAI,QAAQ,0LAA0L,EACtM,oBAAoB,CACrB,CAAC;KACH;AACH,CAAC;AARD,4DAQC;AAEY,QAAA,kBAAkB,GAAG,CAAC,OAAO,EAAE,SAAS,CAAU,CAAC"}
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "@typescript-eslint/rule-tester",
3
+ "version": "6.0.0-alpha.158+b411706a1",
4
+ "description": "Tooling to test ESLint rules",
5
+ "files": [
6
+ "dist",
7
+ "_ts4.2",
8
+ "README.md",
9
+ "LICENSE"
10
+ ],
11
+ "type": "commonjs",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "engines": {
20
+ "node": "^16.0.0 || >=18.0.0"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/typescript-eslint/typescript-eslint.git",
25
+ "directory": "packages/rule-tester"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/typescript-eslint/typescript-eslint/issues"
29
+ },
30
+ "license": "MIT",
31
+ "keywords": [
32
+ "eslint",
33
+ "typescript",
34
+ "estree"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsc -b tsconfig.build.json",
38
+ "postbuild": "downlevel-dts dist _ts4.2/dist --to=4.2",
39
+ "clean": "tsc -b tsconfig.build.json --clean",
40
+ "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage",
41
+ "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
42
+ "lint": "nx lint",
43
+ "pretest-eslint-base": "tsc -b tsconfig.build.json",
44
+ "test-eslint-base": "mocha --require source-map-support/register ./tests/eslint-base/eslint-base.test.js",
45
+ "test": "jest --coverage",
46
+ "typecheck": "tsc -p tsconfig.json --noEmit"
47
+ },
48
+ "//": "NOTE - AJV is out-of-date, but it's intentionally synced with ESLint - https://github.com/eslint/eslint/blob/ad9dd6a933fd098a0d99c6a9aa059850535c23ee/package.json#L70",
49
+ "dependencies": {
50
+ "@typescript-eslint/typescript-estree": "6.0.0-alpha.158+b411706a1",
51
+ "@typescript-eslint/utils": "6.0.0-alpha.158+b411706a1",
52
+ "ajv": "^6.10.0",
53
+ "lodash.merge": "4.6.2",
54
+ "semver": "^7.3.7"
55
+ },
56
+ "peerDependencies": {
57
+ "@eslint/eslintrc": ">=2",
58
+ "eslint": ">=8"
59
+ },
60
+ "devDependencies": {
61
+ "@types/lodash.merge": "4.6.7",
62
+ "@typescript-eslint/parser": "6.0.0-alpha.158+b411706a1",
63
+ "chai": "^4.0.1",
64
+ "mocha": "^8.3.2",
65
+ "sinon": "^11.0.0",
66
+ "source-map-support": "^0.5.21"
67
+ },
68
+ "funding": {
69
+ "type": "opencollective",
70
+ "url": "https://opencollective.com/typescript-eslint"
71
+ },
72
+ "publishConfig": {
73
+ "access": "public"
74
+ },
75
+ "typesVersions": {
76
+ "<3.8": {
77
+ "*": [
78
+ "_ts3.4/*"
79
+ ]
80
+ }
81
+ },
82
+ "gitHead": "b411706a18d85c2f5b84ca6e89c7acd3559d5ec5"
83
+ }