question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interest in adding "no-restricted-glob-paths" rule?

See original GitHub issue
  • no-restricted-paths doesn’t support globs.
  • no-restricted-imports supports globs/git-ignore-like but just as strings, no path resolving support.

So if there is an interested I think I could PR the no-restricted-glob-paths rule. The functionality would be similar to https://github.com/vladimiry/tslint-rules-bunch.

I would prefer to use https://github.com/micromatch/picomatch module for globbing even though the minimatch module is already used. The reason is that picomatch is faster and supports arrays of patterns for both str / pattern arguments on ismatch(str, pattern) function call.

Proposed configuration schema (basePath props both on top/zone levels are optional):

schema: [{
  type: 'object',
  required: ["zones"],
  properties: {
    basePath: {type: ["string"]},
    zones: {
      type: "array",
      minItems: 1,
      items: {
        type: "object",
        required: ["target", "from"],
        properties: {
          basePath: {type: ["string"]},
          target: {
            anyOf: [
              {type: "string"},
              {type: "array", items: {type: "string"}},
            ],
          },
          from: {
            anyOf: [
              {type: "string"},
              {type: "array", items: {type: "string"}},
            ],
          },
        },
        additionalProperties: false,
      },
    },
  },
  additionalProperties: false
}]

Configuration example:

{
  "plugins": [
    "import"
  ],
  "settings": {
    "import/resolver": {
      "typescript": {}
    }
  },
  "rules": {
    "import/no-restricted-glob-paths": [
      "error",
      {
        "zones": [
          {
            "target": "src/electron-main/**/*",
            "from": [
              "./**/*",
              "!./node_modules/**/*",
              "!src/electron-main/**/*",
              "!src/shared/**/*"
            ]
          },
          {
            "basePath": "./src",
            "target": [
              "!./electron-main/database/entity/**/*",
              "!./electron-main/database/validation.ts"
            ],
            "from": [
              "./electron-main/database/entity",
              "./electron-main/database/entity/**/*"
            ]
          }
        ]
      }
    ]
  }
}

#1132 is a possibly related issue, CC @Bessonov

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vladimirycommented, Feb 18, 2020

We could still add the glob support, and then plan to remove except in the future - they seem like they could coexist.

What if we make zones array to include second object type? So we keep existing zones object type and we change nothing in the respective logic. But we add a second object type and apply new logic with glob support for this object. If we go this way then there will be no breaking changes.

So the zones array type would look like:

interface Options {
    zones: Array<
        // currently supported options zone type
        | {
            target: string;
            from: string;
            except?: string[];
        }
        // new options zone type which gets new handling logic
        // that doesn't interfere with existing logic
        | {
            basePath?: string;
            targetGlob: string | string[];
            fromGlob: string | string[];
        }
    >;
}
0reactions
vladimirycommented, Feb 18, 2020

We support down to eslint 2, and need to support the same node versions that a supported version of eslint does

Got it. So v2.20.1 => v6.x eslint-plugin-import bump is not considered.

Unfortunately I would not be interested in implementing glob support in no-restricted-paths using minimatch module having known that there are better options (minimatch by the way doesn’t declare engines.node prop but it runs node 4,6,7 only on Travis). So closing the issue again, this time with won't fix status.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interest in adding "no-restricted-glob-paths" rule? #1662
It seems like the first step would be adding path resolution configuration to no-restricted-imports , and then adding globs to no-restricted- ...
Read more >
Education Department Releases Proposed Regulations to ...
The regulations propose to alleviate student loan debt burdens for borrowers whose schools closed or lied to them, who are totally and ...
Read more >
Use the OS and Glob Python Packages to Manipulate File Paths
The glob() function uses the rules of Unix shell to help users organize their files. Unix shell follows fairly straight-forward rules to search ......
Read more >
Prevent Imports From Being Used With ESLint - Webtips
Based on the paths property, you can pass along a patterns array with the same amount of items specifying a pattern for the...
Read more >
Push rules - GitLab Docs
Override global push rules per project · On the top bar, select Main menu > Projects and find your project. · On the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found