eslint-plugin-turmag-special-rules 0.0.1 → 0.0.2

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
@@ -24,15 +24,15 @@ pnpm add eslint-plugin-turmag-special-rules --save-dev
24
24
 
25
25
  ## Usage
26
26
 
27
- In your [configuration file](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file), import the plugin `eslint-plugin-turmag-special-rules` and add `turmag-eslint-special-rules` to the `plugins` key:
27
+ In your [configuration file](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file), import the plugin `eslint-plugin-turmag-special-rules` and add `turmagEslintSpecialRules` to the `plugins` key:
28
28
 
29
29
  ```js
30
- import turmag-eslint-special-rules from "eslint-plugin-turmag-special-rules";
30
+ import turmagEslintSpecialRules from "eslint-plugin-turmag-special-rules";
31
31
 
32
32
  export default [
33
33
  {
34
34
  plugins: {
35
- turmag-eslint-special-rules
35
+ turmagEslintSpecialRules
36
36
  }
37
37
  }
38
38
  ];
@@ -42,15 +42,15 @@ export default [
42
42
  Then configure the rules you want to use under the `rules` key.
43
43
 
44
44
  ```js
45
- import turmag-eslint-special-rules from "eslint-plugin-turmag-special-rules";
45
+ import turmagEslintSpecialRules from "eslint-plugin-turmag-special-rules";
46
46
 
47
47
  export default [
48
48
  {
49
49
  plugins: {
50
- turmag-eslint-special-rules
50
+ turmagEslintSpecialRules
51
51
  },
52
52
  rules: {
53
- "turmag-eslint-special-rules/rule-name": "warn"
53
+ "turmagEslintSpecialRules/rule-name": "warn"
54
54
  }
55
55
  }
56
56
  ];
@@ -74,6 +74,7 @@ TODO: Run eslint-doc-generator to generate the configs list (or delete this sect
74
74
 
75
75
  | Name                            | Description | 🔧 |
76
76
  | :------------------------------------------------------------------------------- | :------------------------------------------------------------- | :- |
77
+ | [add-vue-extension](docs/rules/add-vue-extension.md) | require .vue in vue files | 🔧 |
77
78
  | [prefer-true-attribute-shorthand](docs/rules/prefer-true-attribute-shorthand.md) | require shorthand form attribute when `v-bind` value is `true` | 🔧 |
78
79
 
79
80
  <!-- end auto-generated rules list -->
@@ -0,0 +1,56 @@
1
+ const path = require('node:path');
2
+ const fs = require('node:fs');
3
+
4
+ module.exports = {
5
+ meta: {
6
+ fixable: 'code',
7
+ type: 'problem',
8
+ docs: {
9
+ description: 'require .vue in vue files',
10
+ },
11
+ messages: {
12
+ proper: 'Use proper import of vue files',
13
+ },
14
+ schema: [{
15
+ type: 'object',
16
+ properties: { aliases: { type: 'object' } },
17
+ }],
18
+ },
19
+ create(context) {
20
+ return {
21
+ ImportDeclaration(node) {
22
+ const aliases = Object.entries(context.options[0].aliases);
23
+ if (!aliases.length) return;
24
+
25
+ const basedir = path.dirname(path.resolve(context.getFilename()));
26
+ let nodeName = node.source.value;
27
+
28
+ aliases.every(([key, value]) => {
29
+ if (nodeName.includes(key)) nodeName = nodeName.replace(key, value);
30
+ else return nodeName === node.source.value;
31
+ });
32
+
33
+ const filePath = path.resolve(basedir, nodeName);
34
+
35
+ const vueExt = '.vue';
36
+ const findRealExtension = filePath => {
37
+ let realExt = fs.existsSync(filePath) ? path.extname(filePath) : null;
38
+ if (realExt === null) realExt = fs.existsSync(`${filePath}${vueExt}`) ? path.extname(`${filePath}${vueExt}`) : null;
39
+
40
+ return realExt;
41
+ };
42
+
43
+ const nodeNameExt = path.extname(nodeName);
44
+ const realExt = findRealExtension(filePath);
45
+
46
+ if (realExt === vueExt && realExt !== nodeNameExt) {
47
+ context.report({
48
+ node,
49
+ messageId: 'proper',
50
+ fix: fixer => fixer.replaceText(node, node.specifiers.map(specifier => `import ${specifier.local.name} from '${node.source.value}${realExt}';`).join('\n')),
51
+ });
52
+ }
53
+ },
54
+ };
55
+ },
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-turmag-special-rules",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Special eslint rules for your awesome projects",
5
5
  "keywords": [
6
6
  "eslint",
@@ -24,8 +24,8 @@
24
24
  "requireindex": "^1.2.0"
25
25
  },
26
26
  "devDependencies": {
27
- "eslint": "^9.0.0",
28
27
  "@eslint/js": "^9.0.0",
28
+ "eslint": "^9.0.0",
29
29
  "eslint-doc-generator": "^1.0.0",
30
30
  "eslint-plugin-eslint-plugin": "^6.0.0",
31
31
  "eslint-plugin-n": "^17.0.0",