@arcgis/eslint-config 5.2.0-next.15 → 5.2.0-next.151

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.
@@ -1,13 +1,13 @@
1
- import { m as makeEslintPlugin } from "../../makePlugin-C2bqt5zI.js";
1
+ import { m as makeEslintPlugin } from "../../chunks/makePlugin.js";
2
2
  import { TSESTree, AST_TOKEN_TYPES, AST_NODE_TYPES, TSESLint } from "@typescript-eslint/utils";
3
3
  import path from "node:path";
4
4
  import { resolve } from "path/posix";
5
5
  import globals from "globals";
6
6
  import { uncapitalize, kebabToPascal } from "@arcgis/toolkit/string";
7
- import { e as extractDeclareElementsInterface, g as getComponentDeclaration } from "../../estree-CDc-die8.js";
7
+ import { e as extractDeclareElementsInterface, k as getComponentDeclaration } from "../../chunks/estree.js";
8
8
  const plugin = makeEslintPlugin(
9
9
  "webgis",
10
- (rule) => `https://devtopia.esri.com/WebGIS/arcgis-web-components/tree/main/packages/support-packages/eslint-config/src/plugins/webgis/rules/${rule}.ts`
10
+ (rule) => `https://devtopia.esri.com/WebGIS/webgis-sdk/tree/main/packages/support-packages/eslint-config/src/plugins/webgis/rules/${rule}.ts`
11
11
  );
12
12
  const isTestFile = (filePath) => filePath.includes("/test") || filePath.includes(".test") || filePath.includes(".spec") || filePath.includes("e2e") || filePath.includes("__") || filePath.includes("/.");
13
13
  const isStorybookFile = (filePath) => filePath.includes(".stories");
@@ -27,7 +27,8 @@ plugin.createRule({
27
27
  // Disabled by default because the rule is most relevant for autocasting
28
28
  // and only on public classes. We are discouraging autocasting in new
29
29
  // code.
30
- defaultLevel: "off"
30
+ defaultLevel: "off",
31
+ isTypeChecked: false
31
32
  },
32
33
  messages: {
33
34
  name: `By convention, the first parameter on an Accessor-based class must be called "properties". This is needed for autocasting - https://webgis.esri.com/references/api-extractor/api-node-kinds#constructor. If your class has constructors overloads, at least one of them must have a "properties" parameter.`,
@@ -77,7 +78,8 @@ If you wish to use a loose type like any/object, create a type alias \`type {{ e
77
78
  return;
78
79
  }
79
80
  const extendsText = node.superClass ? context.sourceCode.getText(node.superClass) : "";
80
- const isCollectionClass = extendsText.includes("Collection.ofType") || extendsText.includes("(Collection)") || extendsText === "Collection" || extendsText === "OwningCollection" || context.filename.endsWith(`esri${path.sep}core${path.sep}Collection.ts`);
81
+ const isCollectionClass = extendsText.includes("Collection.ofType") || extendsText.includes("(Collection)") || extendsText === "Collection" || extendsText === "OwningCollection" || // TODO: drop the esri/ case once core is in the monorepo
82
+ context.filename.endsWith(`esri${path.sep}core${path.sep}Collection.ts`) || context.filename.endsWith(`src${path.sep}core${path.sep}Collection.ts`);
81
83
  if (isCollectionClass) {
82
84
  return;
83
85
  }
@@ -110,13 +112,14 @@ If you wish to use a loose type like any/object, create a type alias \`type {{ e
110
112
  };
111
113
  }
112
114
  });
113
- const description$6 = `Enforce consistent logging so that ArcGIS developers can easily debug errors or warnings logged by our web components, which may lack a meaningful context in compiled code. See [our documentation on @arcgis/toolkit/log](https://webgis.esri.com/references/toolkit/log).`;
115
+ const description$7 = `Enforce consistent logging so that ArcGIS developers can easily debug errors or warnings logged by our web components, which may lack a meaningful context in compiled code. See [our documentation on @arcgis/toolkit/log](https://webgis.esri.com/references/toolkit/log).`;
114
116
  plugin.createRule({
115
117
  name: "consistent-logging",
116
118
  meta: {
117
119
  docs: {
118
- description: description$6,
119
- defaultLevel: "off"
120
+ description: description$7,
121
+ defaultLevel: "off",
122
+ isTypeChecked: false
120
123
  },
121
124
  messages: {
122
125
  consistentLoggingWarning: `For consistency, use the log utility from @arcgis/toolkit/log instead of console.{{logMethodName}}.`
@@ -154,7 +157,8 @@ plugin.createRule({
154
157
  description: "Enforce consistent mixin pattern. See https://webgis.esri.com/sdk/contributing/core/core/mixins",
155
158
  // Enabled by default because the rule targets a very specific pattern
156
159
  // and that pattern is tricky to get right without this rule.
157
- defaultLevel: "error"
160
+ defaultLevel: "error",
161
+ isTypeChecked: false
158
162
  },
159
163
  messages: {
160
164
  updateMixinCode: "Mixin typings need to be updated.",
@@ -479,17 +483,18 @@ function expressionToTypeString(expression, context, asConst) {
479
483
  }
480
484
  return;
481
485
  }
482
- const description$5 = "Using .d.ts files is discouraged. Prefer .ts files instead, as they are type-checked and not in global scope.";
486
+ const description$6 = "Using .d.ts files is discouraged. Prefer .ts files instead, as they are type-checked and not in global scope.";
483
487
  const allowedNames = /* @__PURE__ */ new Set(["vite-env.d.ts", "components.d.ts"]);
484
488
  plugin.createRule({
485
489
  name: "no-dts-files",
486
490
  meta: {
487
491
  docs: {
488
- description: description$5,
489
- defaultLevel: "warn"
492
+ description: description$6,
493
+ defaultLevel: "warn",
494
+ isTypeChecked: false
490
495
  },
491
496
  messages: {
492
- avoidDtsFiles: description$5
497
+ avoidDtsFiles: description$6
493
498
  },
494
499
  type: "suggestion",
495
500
  schema: []
@@ -525,7 +530,8 @@ plugin.createRule({
525
530
  docs: {
526
531
  description: "Disallow empty catch calls since empty catch calls in a promise chain don't catch any exceptions",
527
532
  // Enabled by default because this caught real bugs and has autofix
528
- defaultLevel: "error"
533
+ defaultLevel: "error",
534
+ isTypeChecked: false
529
535
  },
530
536
  messages: { emptyCatch: "no empty catch calls" },
531
537
  schema: [],
@@ -546,16 +552,17 @@ plugin.createRule({
546
552
  };
547
553
  }
548
554
  });
549
- const description$4 = `Imports of files outside the src/ folder are not-portable and likely to break for consumers of this package.`;
555
+ const description$5 = `Imports of files outside the src/ folder are not-portable and likely to break for consumers of this package.`;
550
556
  plugin.createRule({
551
557
  name: "no-import-outside-src",
552
558
  meta: {
553
559
  docs: {
554
- description: description$4,
555
- defaultLevel: "error"
560
+ description: description$5,
561
+ defaultLevel: "error",
562
+ isTypeChecked: false
556
563
  },
557
564
  messages: {
558
- noImportOutsideSrc: description$4
565
+ noImportOutsideSrc: description$5
559
566
  },
560
567
  type: "problem",
561
568
  schema: []
@@ -597,7 +604,8 @@ plugin.createRule({
597
604
  // Disabling by default because this matters for
598
605
  // lower-level libraries more than higher-level libraries or applications.
599
606
  // Also, many false-positives.
600
- defaultLevel: "off"
607
+ defaultLevel: "off",
608
+ isTypeChecked: false
601
609
  },
602
610
  schema: [
603
611
  {
@@ -658,8 +666,23 @@ function isAllowedIdentifier(name, scope, options) {
658
666
  if (builtInTypes.has(name) && isUnshadowedBuiltIn(variable)) {
659
667
  return true;
660
668
  }
669
+ if (isImportVariable(variable) && hasValueReferenceOutsideInstanceOf(variable)) {
670
+ return true;
671
+ }
661
672
  return isClassVariable(variable);
662
673
  }
674
+ function isImportVariable(variable) {
675
+ return variable?.defs.some((definition) => definition.type === TSESLint.Scope.DefinitionType.ImportBinding) ?? false;
676
+ }
677
+ function hasValueReferenceOutsideInstanceOf(variable) {
678
+ return variable.references.some(
679
+ (reference) => reference.isValueReference && reference.identifier.type === AST_NODE_TYPES.Identifier && !isInstanceOfRightOperand(reference.identifier)
680
+ );
681
+ }
682
+ function isInstanceOfRightOperand(identifier) {
683
+ const parent = identifier.parent;
684
+ return parent.type === AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.right === identifier;
685
+ }
663
686
  function isUnshadowedBuiltIn(variable) {
664
687
  if (!variable) {
665
688
  return true;
@@ -683,15 +706,69 @@ function isClassDefinition(definition) {
683
706
  }
684
707
  return variableNode.init?.type === AST_NODE_TYPES.ClassExpression;
685
708
  }
709
+ const description$4 = "For Node.js compatibility, when TypeScript file imports another TypeScript file, use .ts extension over .js";
710
+ plugin.createRule({
711
+ name: "no-js-in-ts-imports",
712
+ meta: {
713
+ docs: {
714
+ description: description$4,
715
+ defaultLevel: "off",
716
+ isTypeChecked: false
717
+ },
718
+ messages: {
719
+ noJsInTsImports: description$4
720
+ },
721
+ type: "problem",
722
+ fixable: "code",
723
+ schema: []
724
+ },
725
+ defaultOptions: [],
726
+ create(context) {
727
+ if (!/\.tsx?$/u.test(context.filename)) {
728
+ return {};
729
+ }
730
+ function checkSpecifier(node) {
731
+ const specifier = node.value;
732
+ if (!(specifier.startsWith("./") || specifier.startsWith("../")) || !specifier.endsWith(".js")) {
733
+ return;
734
+ }
735
+ context.report({
736
+ node,
737
+ messageId: "noJsInTsImports",
738
+ data: { specifier },
739
+ fix: (fixer) => fixer.replaceTextRange([node.range[1] - 3, node.range[1] - 1], "ts")
740
+ });
741
+ }
742
+ return {
743
+ ImportDeclaration(node) {
744
+ checkSpecifier(node.source);
745
+ },
746
+ ImportExpression(node) {
747
+ if (node.source.type === AST_NODE_TYPES.Literal && typeof node.source.value === "string") {
748
+ checkSpecifier(node.source);
749
+ }
750
+ },
751
+ ExportAllDeclaration(node) {
752
+ checkSpecifier(node.source);
753
+ },
754
+ ExportNamedDeclaration(node) {
755
+ if (node.source) {
756
+ checkSpecifier(node.source);
757
+ }
758
+ }
759
+ };
760
+ }
761
+ });
686
762
  plugin.createRule({
687
763
  name: "no-kebab-case-props",
688
764
  meta: {
689
765
  docs: {
690
766
  description: "Disallow kebab-case props on custom JSX elements.",
691
767
  // Off by default till
692
- // https://devtopia.esri.com/WebGIS/arcgis-web-components/issues/5364#issuecomment-6321339
768
+ // https://devtopia.esri.com/WebGIS/webgis-sdk/issues/5364#issuecomment-6321339
693
769
  // is resolved
694
- defaultLevel: "off"
770
+ defaultLevel: "off",
771
+ isTypeChecked: false
695
772
  },
696
773
  messages: {
697
774
  kebab: "JSX props should use camelCase instead of kebab-case, except for data- or aria- attributes"
@@ -748,7 +825,8 @@ plugin.createRule({
748
825
  meta: {
749
826
  docs: {
750
827
  description: description$3,
751
- defaultLevel: "off"
828
+ defaultLevel: "off",
829
+ isTypeChecked: false
752
830
  },
753
831
  messages: {
754
832
  noStoryRenderArgsTypeAnnotation: "Do not annotate `render(args)` in stories. Type the story with `Meta<T>` or `StoryObj<T>` and let `args` infer from that."
@@ -789,7 +867,8 @@ plugin.createRule({
789
867
  meta: {
790
868
  docs: {
791
869
  description: description$2,
792
- defaultLevel: "warn"
870
+ defaultLevel: "error",
871
+ isTypeChecked: false
793
872
  },
794
873
  messages: {
795
874
  noTouchingJsDoc: description$2
@@ -834,7 +913,8 @@ plugin.createRule({
834
913
  meta: {
835
914
  docs: {
836
915
  description: description$1,
837
- defaultLevel: "warn"
916
+ defaultLevel: "error",
917
+ isTypeChecked: false
838
918
  },
839
919
  messages: {
840
920
  error: description$1
@@ -889,7 +969,8 @@ plugin.createRule({
889
969
  docs: {
890
970
  description: "Async tests must await a screenshot assertion.",
891
971
  // Enabled by default because it targets a specific pattern and has autofix
892
- defaultLevel: "error"
972
+ defaultLevel: "error",
973
+ isTypeChecked: false
893
974
  },
894
975
  messages: { asyncAssert: "Async tests must await a screenshot assertion." },
895
976
  schema: [],
@@ -922,7 +1003,8 @@ plugin.createRule({
922
1003
  // presumably work correctly today) so enabling it is a bit too disruptive.
923
1004
  // We should coordinate enabling it with enabling other lint rules to
924
1005
  // announce at once.
925
- defaultLevel: "off"
1006
+ defaultLevel: "off",
1007
+ isTypeChecked: false
926
1008
  },
927
1009
  messages: { missingType: "An explicit type attribute is required on buttons" },
928
1010
  schema: [],
@@ -944,17 +1026,18 @@ plugin.createRule({
944
1026
  };
945
1027
  }
946
1028
  });
947
- const description = `@arcgis/core imports need to end with .js for better compatibility with ESM CDN builds for @arcgis/core and other packages.`;
948
- const packagesToEnforce = ["@arcgis/core/", "@amcharts/amcharts4/", "@amcharts/amcharts5/"];
1029
+ const description = `Imports of certain packages need to end with .js for better compatibility with CDN and bundlers.`;
1030
+ const packagesToEnforce = ["@arcgis/core/", "@amcharts/amcharts4/", "@amcharts/amcharts5/", "@vaadin/grid/"];
949
1031
  plugin.createRule({
950
1032
  name: "require-js-in-imports",
951
1033
  meta: {
952
1034
  docs: {
953
1035
  description,
954
- defaultLevel: "warn"
1036
+ defaultLevel: "warn",
1037
+ isTypeChecked: false
955
1038
  },
956
1039
  messages: {
957
- requireJsInCoreImport: description
1040
+ requireJsInImports: description
958
1041
  },
959
1042
  type: "problem",
960
1043
  fixable: "code",
@@ -978,7 +1061,7 @@ plugin.createRule({
978
1061
  }
979
1062
  context.report({
980
1063
  node: node.source,
981
- messageId: "requireJsInCoreImport",
1064
+ messageId: "requireJsInImports",
982
1065
  fix: (fixer) => fixer.replaceText(node.source, `"${specifier}.js"`)
983
1066
  });
984
1067
  }
@@ -988,6 +1071,63 @@ plugin.createRule({
988
1071
  };
989
1072
  }
990
1073
  });
1074
+ plugin.createRule({
1075
+ name: "require-ts-in-imports",
1076
+ meta: {
1077
+ docs: {
1078
+ description: "Require configured packages to be imported through their TypeScript source entrypoints when built output may be unavailable.",
1079
+ defaultLevel: "off",
1080
+ isTypeChecked: false
1081
+ },
1082
+ messages: {
1083
+ requireTsInImports: "Import '{{specifier}}' through its '/ts' source entrypoint because built output for '{{packageName}}' may not yet be available when current package is invoked."
1084
+ },
1085
+ type: "problem",
1086
+ schema: [
1087
+ {
1088
+ type: "array",
1089
+ items: { type: "string" },
1090
+ uniqueItems: true
1091
+ }
1092
+ ]
1093
+ },
1094
+ defaultOptions: [[]],
1095
+ create(context) {
1096
+ const packageNames = context.options[0];
1097
+ function checkSpecifier(node) {
1098
+ const specifier = node.value;
1099
+ const packageName = packageNames.find(
1100
+ (candidate) => specifier === candidate || specifier.startsWith(`${candidate}/`)
1101
+ );
1102
+ if (packageName === void 0 || specifier === `${packageName}/package.json` || specifier.endsWith("/ts")) {
1103
+ return;
1104
+ }
1105
+ context.report({
1106
+ node,
1107
+ messageId: "requireTsInImports",
1108
+ data: { packageName, specifier }
1109
+ });
1110
+ }
1111
+ return {
1112
+ ImportDeclaration(node) {
1113
+ checkSpecifier(node.source);
1114
+ },
1115
+ ImportExpression(node) {
1116
+ if (node.source.type === AST_NODE_TYPES.Literal && typeof node.source.value === "string") {
1117
+ checkSpecifier(node.source);
1118
+ }
1119
+ },
1120
+ ExportAllDeclaration(node) {
1121
+ checkSpecifier(node.source);
1122
+ },
1123
+ ExportNamedDeclaration(node) {
1124
+ if (node.source) {
1125
+ checkSpecifier(node.source);
1126
+ }
1127
+ }
1128
+ };
1129
+ }
1130
+ });
991
1131
  const webgisPlugin = plugin.finalize();
992
1132
  export {
993
1133
  webgisPlugin
@@ -4,7 +4,8 @@ import type { TSESLint } from "@typescript-eslint/utils";
4
4
  * A utility for temporary running ESLint with only specific rules enabled.
5
5
  *
6
6
  * @param config - flat config
7
- * @param enabledRules - exceptions
7
+ * @param enabledRules - exceptions. Set a rule to `true` to preserve existing
8
+ * configuration
8
9
  * @param disableTypeChecking - make ESLint much faster by temporary disabling
9
10
  * type-aware linting.
10
11
  * @returns a new flat config array where every rule is disabled,
@@ -21,4 +22,4 @@ import type { TSESLint } from "@typescript-eslint/utils";
21
22
  * true,
22
23
  * );
23
24
  */
24
- export function disableAllRulesExcept(config: TSESLint.FlatConfig.ConfigArray, enabledRules: Record<string, TSESLint.FlatConfig.RuleLevel>, disableTypeChecking: boolean): TSESLint.FlatConfig.ConfigArray;
25
+ export function disableAllRulesExcept(config: TSESLint.FlatConfig.ConfigArray, enabledRules: Partial<Record<string, TSESLint.FlatConfig.RuleEntry | true>>, disableTypeChecking: boolean): TSESLint.FlatConfig.ConfigArray;
@@ -10,7 +10,7 @@ function applyRulesAndOptions(entry, enabledRules, disableTypeChecking) {
10
10
  rules: Object.fromEntries(
11
11
  Object.keys(entry.rules).map((ruleName) => {
12
12
  const override = enabledRules[ruleName];
13
- return [ruleName, override ?? "off"];
13
+ return [ruleName, override === true ? entry.rules[ruleName] : override ?? "off"];
14
14
  })
15
15
  )
16
16
  } : entry;
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@arcgis/eslint-config",
3
- "version": "5.2.0-next.15",
3
+ "version": "5.2.0-next.151",
4
4
  "description": "ESLint configuration for WebGIS SDK",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./dist/config/index.js",
8
8
  "./application": "./dist/config/applications.js",
9
+ "./core": "./dist/config/core.js",
9
10
  "./extra": "./dist/config/extra.js",
10
11
  "./lumina": "./dist/config/lumina.js",
11
12
  "./plugins/core": "./dist/plugins/core/index.js",
@@ -20,24 +21,28 @@
20
21
  ],
21
22
  "license": "SEE LICENSE IN LICENSE.md",
22
23
  "dependencies": {
23
- "@eslint/js": "^10.0.1",
24
- "@eslint/markdown": "^8.0.1",
24
+ "@arcgis/toolkit": "5.2.0-next.151",
25
+ "@eslint/markdown": "^8.0.3",
25
26
  "@types/confusing-browser-globals": "^1.0.3",
26
- "@typescript-eslint/utils": "^8.58.0",
27
+ "@typescript-eslint/utils": "^8.63.0",
27
28
  "confusing-browser-globals": "^1.0.11",
28
- "eslint-import-resolver-typescript": "^4.4.4",
29
- "eslint-plugin-import-x": "^4.16.2",
29
+ "eslint-import-resolver-typescript": "^4.4.5",
30
+ "eslint-plugin-import-x": "^4.17.1",
31
+ "eslint-plugin-jsdoc": "~63.0.13",
30
32
  "eslint-plugin-package-json": "~0.91.1",
33
+ "eslint-plugin-perfectionist": "~5.10.0",
34
+ "eslint-plugin-react-jsx": "~5.11.2",
35
+ "eslint-plugin-regexp": "~3.1.1",
31
36
  "eslint-plugin-storybook": "^10.3.4",
37
+ "eslint-plugin-unicorn": "~64.0.0",
32
38
  "globals": "^16.5.0",
33
39
  "jsonc-eslint-parser": "^3.1.0",
34
40
  "prettier-linter-helpers": "^1.0.1",
35
41
  "tslib": "^2.8.1",
36
- "typescript": "~6.0.2",
37
- "typescript-eslint": "^8.58.0",
38
- "@arcgis/toolkit": "5.2.0-next.15"
42
+ "typescript": "~6.0.3",
43
+ "typescript-eslint": "^8.63.0"
39
44
  },
40
45
  "peerDependencies": {
41
- "eslint": "^10.2.0"
46
+ "eslint": "^10.6.0"
42
47
  }
43
48
  }