eslint-plugin-absolute 0.11.0-beta.1 → 0.11.0-beta.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.
Files changed (2) hide show
  1. package/dist/index.js +82 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3653,6 +3653,20 @@ var noRedundantTypeAnnotation = createRule({
3653
3653
  return {};
3654
3654
  }
3655
3655
  const stringify = (type) => tsChecker.typeToString(type, undefined, ts2.TypeFormatFlags.NoTruncation | ts2.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
3656
+ const referencesTypeParam = (typeNode, name) => {
3657
+ let found = false;
3658
+ const visit = (node) => {
3659
+ if (found)
3660
+ return;
3661
+ if (ts2.isTypeReferenceNode(node) && ts2.isIdentifier(node.typeName) && node.typeName.text === name) {
3662
+ found = true;
3663
+ return;
3664
+ }
3665
+ ts2.forEachChild(node, visit);
3666
+ };
3667
+ visit(typeNode);
3668
+ return found;
3669
+ };
3656
3670
  const leansOnContextualInference = (initNode) => {
3657
3671
  const callLike = ts2.isCallExpression(initNode) || ts2.isNewExpression(initNode) ? initNode : null;
3658
3672
  if (!callLike)
@@ -3660,6 +3674,14 @@ var noRedundantTypeAnnotation = createRule({
3660
3674
  if (callLike.typeArguments && callLike.typeArguments.length > 0) {
3661
3675
  return false;
3662
3676
  }
3677
+ const resolved = tsChecker.getResolvedSignature(callLike);
3678
+ const declaration = resolved?.declaration;
3679
+ if (declaration && !ts2.isJSDocSignature(declaration)) {
3680
+ const typeParams = declaration.typeParameters;
3681
+ if (!typeParams || typeParams.length === 0)
3682
+ return false;
3683
+ return typeParams.some((typeParam) => !declaration.parameters.some((parameter) => parameter.type !== undefined && referencesTypeParam(parameter.type, typeParam.name.text)));
3684
+ }
3663
3685
  const calleeType = tsChecker.getTypeAtLocation(callLike.expression);
3664
3686
  const signatures = ts2.isNewExpression(callLike) ? calleeType.getConstructSignatures() : calleeType.getCallSignatures();
3665
3687
  return signatures.some((signature) => (signature.getTypeParameters()?.length ?? 0) > 0);
@@ -3722,6 +3744,65 @@ var noRedundantTypeAnnotation = createRule({
3722
3744
  name: "no-redundant-type-annotation"
3723
3745
  });
3724
3746
 
3747
+ // src/rules/no-import-meta-path.ts
3748
+ var FILESYSTEM_PATH_PROPERTIES = new Set(["dir", "dirname", "filename"]);
3749
+ var isImportMeta = (node) => node.type === "MetaProperty" && node.meta.name === "import" && node.property.name === "meta";
3750
+ var importMetaProperty = (node) => {
3751
+ if (!isImportMeta(node.object))
3752
+ return null;
3753
+ if (node.computed || node.property.type !== "Identifier")
3754
+ return null;
3755
+ return node.property.name;
3756
+ };
3757
+ var calleeName = (callee) => {
3758
+ if (callee.type === "Identifier")
3759
+ return callee.name;
3760
+ if (callee.type === "MemberExpression" && callee.property.type === "Identifier") {
3761
+ return callee.property.name;
3762
+ }
3763
+ return null;
3764
+ };
3765
+ var noImportMetaPath = createRule({
3766
+ create(context) {
3767
+ return {
3768
+ CallExpression(node) {
3769
+ if (calleeName(node.callee) !== "fileURLToPath")
3770
+ return;
3771
+ const urlArgument = node.arguments.find((argument) => argument.type === "MemberExpression" && importMetaProperty(argument) === "url");
3772
+ if (urlArgument) {
3773
+ context.report({
3774
+ messageId: "importMetaUrl",
3775
+ node: urlArgument
3776
+ });
3777
+ }
3778
+ },
3779
+ MemberExpression(node) {
3780
+ const property = importMetaProperty(node);
3781
+ if (property && FILESYSTEM_PATH_PROPERTIES.has(property)) {
3782
+ context.report({
3783
+ data: { property },
3784
+ messageId: "importMetaPath",
3785
+ node
3786
+ });
3787
+ }
3788
+ }
3789
+ };
3790
+ },
3791
+ defaultOptions: [],
3792
+ meta: {
3793
+ docs: {
3794
+ description: "Disallow deriving filesystem paths from a module's own location (`import.meta.dir`/`dirname`/`filename`, `fileURLToPath(import.meta.url)`). They move when the server is bundled, so paths break in `absolute start`. Anchor to `projectRoot` from @absolutejs/absolute or `process.cwd()`."
3795
+ },
3796
+ messages: {
3797
+ importMetaPath: "`import.meta.{{property}}` resolves this module's own location, which is your src/ tree in `absolute dev` but the bundled dist/ in `absolute start` \u2014 module-relative paths silently break in production. Anchor runtime/data paths to `projectRoot` from @absolutejs/absolute (or `process.cwd()`).",
3798
+ importMetaUrl: "`fileURLToPath(import.meta.url)` derives a filesystem path from this module's own location, which moves when the server is bundled (src/ in `absolute dev`, dist/ in `absolute start`) \u2014 so the path silently breaks in production. Anchor runtime/data paths to `projectRoot` from @absolutejs/absolute (or `process.cwd()`)."
3799
+ },
3800
+ schema: [],
3801
+ type: "problem"
3802
+ },
3803
+ name: "no-import-meta-path"
3804
+ });
3805
+
3725
3806
  // src/rules/no-trivial-alias.ts
3726
3807
  var isBareTypeReference = (node) => {
3727
3808
  if (node.type === "TSTypeReference") {
@@ -3973,6 +4054,7 @@ var src_default = {
3973
4054
  "min-var-length": minVarLength,
3974
4055
  "no-button-navigation": noButtonNavigation,
3975
4056
  "no-explicit-return-type": noExplicitReturnTypes,
4057
+ "no-import-meta-path": noImportMetaPath,
3976
4058
  "no-inline-object-types": noInlineObjectTypes,
3977
4059
  "no-multi-style-objects": noMultiStyleObjects,
3978
4060
  "no-nested-jsx-return": noNestedJSXReturn,
package/package.json CHANGED
@@ -40,5 +40,5 @@
40
40
  "typecheck": "bun run tsc --noEmit"
41
41
  },
42
42
  "type": "module",
43
- "version": "0.11.0-beta.1"
43
+ "version": "0.11.0-beta.3"
44
44
  }