eslint-plugin-fsd-paths-check 0.0.4 → 0.0.6

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,6 +1,6 @@
1
1
  # eslint-plugin-path-check
2
2
 
3
- plugin to check typescript imports
3
+ Plugin to check feature sliced design paths correctness
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,24 +10,23 @@ You'll first need to install [ESLint](https://eslint.org/):
10
10
  npm i eslint --save-dev
11
11
  ```
12
12
 
13
- Next, install `eslint-plugin-path-check`:
13
+ Next, install `eslint-plugin-fsd-paths-check`:
14
14
 
15
15
  ```sh
16
- npm install eslint-plugin-path-check --save-dev
16
+ npm install eslint-plugin-fsd-paths-check --save-dev
17
17
  ```
18
18
 
19
19
  ## Usage
20
20
 
21
- In your [configuration file](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file), import the plugin `eslint-plugin-path-check` and add `path-check` to the `plugins` key:
21
+ In your [configuration file](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file), import the plugin `eslint-plugin-fsd-paths-check` and add `fsd-paths-check` to the `plugins` key:
22
22
 
23
23
  ```js
24
24
  import { defineConfig } from "eslint/config";
25
- import path-check from "eslint-plugin-path-check";
26
25
 
27
26
  export default defineConfig([
28
27
  {
29
28
  plugins: {
30
- path-check
29
+ [`fsd-paths-check`]
31
30
  }
32
31
  }
33
32
  ]);
@@ -38,15 +37,14 @@ Then configure the rules you want to use under the `rules` key.
38
37
 
39
38
  ```js
40
39
  import { defineConfig } from "eslint/config";
41
- import path-check from "eslint-plugin-path-check";
42
40
 
43
41
  export default defineConfig([
44
42
  {
45
43
  plugins: {
46
- path-check
44
+ [`fsd-paths-check`]
47
45
  },
48
46
  rules: {
49
- "path-check/rule-name": "warn"
47
+ "fsd-paths-check/rule-name": "warn"
50
48
  }
51
49
  }
52
50
  ]);
@@ -11,16 +11,27 @@ module.exports = {
11
11
  url: null, // URL to the documentation page for this rule
12
12
  },
13
13
  fixable: `code`,
14
- schema: [], // Add a schema if the rule has options
14
+ schema: [
15
+ {
16
+ type: `object`,
17
+ properties: {
18
+ alias: {
19
+ type: `string`,
20
+ }
21
+ }
22
+ }
23
+ ],
15
24
  messages: {
16
25
  useRelativePathWithinSlice: `Imports within the slice should be relative`
17
26
  },
18
27
  },
19
28
 
20
29
  create(context) {
30
+ const alias = context.options[0]?.alias ?? ``;
21
31
  return {
22
32
  ImportDeclaration(node) {
23
- const importTo = node.source.value;
33
+ const value = node.source.value;
34
+ const importTo = alias ? value.replace(`${alias}`, ``) : value;
24
35
  const currentFile = context.getFilename();
25
36
 
26
37
  if(shouldBeRelative(currentFile, importTo)) {
@@ -30,9 +41,10 @@ module.exports = {
30
41
  fix(fixer) {
31
42
  const projectFromPath = getProjectPath(currentFile);
32
43
  const currentDir = path.dirname(projectFromPath);
33
- const relativePath = path.relative(currentDir, node.source.value);
44
+ const relativePath = path.relative(currentDir, importTo);
45
+ const finalRelativePath = relativePath.startsWith(`.`) ? relativePath : `./${relativePath}`;
34
46
 
35
- return fixer.replaceText(node.source, `"${relativePath}"`);
47
+ return fixer.replaceText(node.source, `'${finalRelativePath}'`);
36
48
  }
37
49
  });
38
50
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-fsd-paths-check",
3
- "version": "0.0.4",
4
- "description": "plugin to check feature sliced design paths correctness",
3
+ "version": "0.0.6",
4
+ "description": "Plugin to check feature sliced design paths correctness",
5
5
  "keywords": [
6
6
  "eslint",
7
7
  "eslintplugin",