eslint-plugin-turmag-special-rules 0.0.1

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 ADDED
@@ -0,0 +1,81 @@
1
+ # eslint-plugin-turmag-special-rules
2
+
3
+ Special eslint rules for your awesome projects
4
+
5
+ ## Installation
6
+
7
+ You'll first need to install [ESLint](https://eslint.org/):
8
+
9
+ ```sh
10
+ npm i eslint --save-dev
11
+ ```
12
+
13
+ Next, install `eslint-plugin-turmag-special-rules`:
14
+
15
+ ```sh
16
+ npm install eslint-plugin-turmag-special-rules --save-dev
17
+
18
+ # Or run this to use yarn
19
+ yarn add eslint-plugin-turmag-special-rules --dev
20
+
21
+ # Or run this to use pnpm
22
+ pnpm add eslint-plugin-turmag-special-rules --save-dev
23
+ ```
24
+
25
+ ## Usage
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:
28
+
29
+ ```js
30
+ import turmag-eslint-special-rules from "eslint-plugin-turmag-special-rules";
31
+
32
+ export default [
33
+ {
34
+ plugins: {
35
+ turmag-eslint-special-rules
36
+ }
37
+ }
38
+ ];
39
+ ```
40
+
41
+
42
+ Then configure the rules you want to use under the `rules` key.
43
+
44
+ ```js
45
+ import turmag-eslint-special-rules from "eslint-plugin-turmag-special-rules";
46
+
47
+ export default [
48
+ {
49
+ plugins: {
50
+ turmag-eslint-special-rules
51
+ },
52
+ rules: {
53
+ "turmag-eslint-special-rules/rule-name": "warn"
54
+ }
55
+ }
56
+ ];
57
+ ```
58
+
59
+
60
+
61
+ ## Configurations
62
+
63
+ <!-- begin auto-generated configs list -->
64
+ TODO: Run eslint-doc-generator to generate the configs list (or delete this section if no configs are offered).
65
+ <!-- end auto-generated configs list -->
66
+
67
+
68
+
69
+ ## Rules
70
+
71
+ <!-- begin auto-generated rules list -->
72
+
73
+ 🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
74
+
75
+ | Name                            | Description | 🔧 |
76
+ | :------------------------------------------------------------------------------- | :------------------------------------------------------------- | :- |
77
+ | [prefer-true-attribute-shorthand](docs/rules/prefer-true-attribute-shorthand.md) | require shorthand form attribute when `v-bind` value is `true` | 🔧 |
78
+
79
+ <!-- end auto-generated rules list -->
80
+
81
+
package/lib/index.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @fileoverview Special eslint rules for your awesome projects
3
+ * @author Pavel
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const requireIndex = require("requireindex");
12
+
13
+ //------------------------------------------------------------------------------
14
+ // Plugin Definition
15
+ //------------------------------------------------------------------------------
16
+
17
+
18
+ // import all rules in lib/rules
19
+ module.exports.rules = requireIndex(__dirname + "/rules");
20
+
21
+
22
+
@@ -0,0 +1,49 @@
1
+ module.exports = {
2
+ meta: {
3
+ fixable: 'code',
4
+ type: 'problem',
5
+ docs: {
6
+ description:
7
+ 'require shorthand form attribute when `v-bind` value is `true`',
8
+ },
9
+ messages: {
10
+ shortHand: 'Boolean prop with \'true\' value should be written in shorthand form',
11
+ longHand: 'Boolean prop with \'true\' value should be written in longhand form',
12
+ },
13
+ schema: [{ enum: ['always', 'never'] }],
14
+ },
15
+ create(context) {
16
+ const sourceCode = context.getSourceCode();
17
+ return sourceCode.parserServices?.defineTemplateBodyVisitor
18
+ ? sourceCode.parserServices.defineTemplateBodyVisitor({
19
+ VAttribute(node) {
20
+ const option = context.options[0] || 'always';
21
+
22
+ if (option === 'never' && !node.directive && !node.value) {
23
+ context.report({
24
+ node,
25
+ messageId: 'longHand',
26
+ fix: fixer => fixer.replaceText(node, `:${node.key.rawName}="true"`),
27
+ });
28
+ }
29
+
30
+ if (option !== 'always') return;
31
+
32
+ if (node.directive && node.key.name !== 'bind' && node.value?.expression.value && node.value.expression.value === Boolean(node.value.expression.value)) {
33
+ const { argument } = node.key;
34
+ if (!argument) return;
35
+
36
+ context.report({
37
+ node,
38
+ messageId: 'shortHand',
39
+ fix: fixer => {
40
+ const sourceCode = context.getSourceCode();
41
+ return fixer.replaceText(node, sourceCode.getText(argument));
42
+ },
43
+ });
44
+ }
45
+ },
46
+ })
47
+ : {};
48
+ },
49
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "eslint-plugin-turmag-special-rules",
3
+ "version": "0.0.1",
4
+ "description": "Special eslint rules for your awesome projects",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslintplugin",
8
+ "eslint-plugin"
9
+ ],
10
+ "author": "Pavel",
11
+ "main": "./lib/index.js",
12
+ "exports": "./lib/index.js",
13
+ "files": [
14
+ "lib"
15
+ ],
16
+ "scripts": {
17
+ "lint": "npm-run-all \"lint:*\"",
18
+ "lint:eslint-docs": "npm-run-all \"update:eslint-docs -- --check\"",
19
+ "lint:js": "eslint .",
20
+ "test": "mocha tests --recursive",
21
+ "update:eslint-docs": "eslint-doc-generator"
22
+ },
23
+ "dependencies": {
24
+ "requireindex": "^1.2.0"
25
+ },
26
+ "devDependencies": {
27
+ "eslint": "^9.0.0",
28
+ "@eslint/js": "^9.0.0",
29
+ "eslint-doc-generator": "^1.0.0",
30
+ "eslint-plugin-eslint-plugin": "^6.0.0",
31
+ "eslint-plugin-n": "^17.0.0",
32
+ "mocha": "^10.0.0",
33
+ "npm-run-all2": "^6.1.2"
34
+ },
35
+ "engines": {
36
+ "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
37
+ },
38
+ "peerDependencies": {
39
+ "eslint": ">=8.57.0"
40
+ },
41
+ "license": "MIT"
42
+ }