@testgorilla/tgo-linting 1.0.0 → 1.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
@@ -5,99 +5,192 @@ Linting rules and code quality standards for TestGorilla projects.
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @testgorilla/tgo-linting --save-dev
8
+ npm install @testgorilla/tgo-linting @angular-eslint/template-parser --save-dev
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
- Add the plugin to your ESLint configuration:
13
+ This package supports both modern flat config (ESLint 9+) and legacy config formats (ESLint 8.x and below).
14
14
 
15
15
  ### Flat Config (ESLint 9+)
16
16
 
17
+ **Recommended approach:**
18
+
17
19
  ```javascript
20
+ // eslint.config.js
18
21
  import tgoPlugin from '@testgorilla/tgo-linting';
19
22
 
20
23
  export default [
21
- {
22
- plugins: {
23
- tgo: tgoPlugin,
24
- },
25
- rules: {
26
- 'tgo/require-data-testid': 'warn',
27
- },
28
- },
24
+ tgoPlugin.configs.recommended,
25
+ // Your other configurations
29
26
  ];
30
27
  ```
31
28
 
32
- ### Or use the recommended configuration:
29
+ **Manual configuration:**
33
30
 
34
31
  ```javascript
32
+ // eslint.config.js
35
33
  import tgoPlugin from '@testgorilla/tgo-linting';
36
34
 
37
35
  export default [
38
- tgoPlugin.configs.recommended,
39
- // Your other configurations
36
+ {
37
+ plugins: {
38
+ tgo: tgoPlugin,
39
+ },
40
+ rules: {
41
+ 'tgo/require-data-testid': 'warn', // Example rule configuration
42
+ },
43
+ },
40
44
  ];
41
45
  ```
42
46
 
43
- ## Rules
44
-
45
- ### `tgo/require-data-testid`
46
-
47
- Ensures that specific HTML elements have a `data-testid` attribute for testing purposes.
48
-
49
- **Note:** This rule requires an ESLint setup that parses template ASTs (e.g., `@angular-eslint/template-parser` for Angular projects). It will not run against plain JS/TS ASTs.
50
-
51
- #### Default Elements
47
+ ### Legacy Config (ESLint 8.x and below)
52
48
 
53
- By default, this rule checks the following elements:
54
- - `button`
55
- - `mat-checkbox`
56
- - `input`
57
- - `mat-radio-button`
58
- - `mat-radio-group`
59
- - `h1`
60
- - `table`, `header-table`, `mat-table`
61
- - `img`
62
- - `textarea`
63
- - `ng-select`
64
- - `video`
65
- - `app-tgo-choice`
66
- - `testgorilla-confirm-dialog`
67
- - `mat-form-field`
68
- - `tgo-checkout-message`
69
- - `mat-dialog-actions`
70
- - `ui-button`
49
+ **Using the legacy preset:**
71
50
 
72
- #### Configuration
51
+ ```javascript
52
+ // .eslintrc.js
53
+ const { legacy } = require('@testgorilla/tgo-linting');
54
+
55
+ module.exports = {
56
+ // Your base config
57
+ extends: [
58
+ // Your other extends
59
+ ],
60
+ plugins: ['tgo'],
61
+ overrides: [
62
+ {
63
+ files: ['*.html'],
64
+ parser: '@angular-eslint/template-parser',
65
+ ...legacy,
66
+ },
67
+ ],
68
+ };
69
+ ```
73
70
 
74
- You can customize which elements to check:
71
+ **Manual configuration:**
75
72
 
76
73
  ```javascript
77
- {
78
- rules: {
79
- 'tgo/require-data-testid': ['warn', {
80
- tags: ['button', 'input', 'custom-element']
81
- }]
82
- }
83
- }
74
+ // .eslintrc.js
75
+ module.exports = {
76
+ plugins: ['tgo'],
77
+ extends: [
78
+ // Your other extends
79
+ ],
80
+ overrides: [
81
+ {
82
+ files: ['*.html'],
83
+ parser: '@angular-eslint/template-parser',
84
+ rules: {
85
+ 'tgo/require-data-testid': 'warn', // Example rule configuration
86
+ },
87
+ },
88
+ ],
89
+ };
84
90
  ```
85
91
 
86
- #### Examples
92
+ ## Important Notes
87
93
 
88
- ❌ **Incorrect**
94
+ - **Template Parser Required:** The `tgo/require-data-testid` rule only works with HTML/Angular templates. You must configure `@angular-eslint/template-parser` for `.html` files.
95
+ - **Angular Projects:** If you're using `@angular-eslint`, the template parser is usually already configured for HTML files in your overrides.
89
96
 
90
- ```html
91
- <button>Click me</button>
92
- <input type="text" />
93
- ```
94
-
95
- ✅ **Correct**
97
+ ## Rules
96
98
 
97
- ```html
98
- <button data-testid="submit-button">Click me</button>
99
- <input type="text" data-testid="email-input" />
100
- ```
99
+ ### Available Rules
100
+
101
+ | Rule | Description |
102
+ |------|-------------|
103
+ | `tgo/require-data-testid` | Ensures specific HTML elements have a `data-testid` attribute for E2E testing |
104
+
105
+ ### Rule Documentation
106
+
107
+ Detailed documentation for each rule, including examples and configuration options, can be found alongside the rule implementation:
108
+
109
+ - [require-data-testid](./src/rules/require-data-testid.md) - Enforces data-testid attributes on specified elements
110
+
111
+ ## Adding New Rules
112
+
113
+ To add a new ESLint rule to this package:
114
+
115
+ 1. **Create the rule file** in `src/rules/`:
116
+ ```typescript
117
+ // src/rules/your-rule-name.ts
118
+ import { Rule } from 'eslint'
119
+
120
+ const rule: Rule.RuleModule = {
121
+ meta: {
122
+ type: 'problem', // or 'suggestion' or 'layout'
123
+ docs: {
124
+ description: 'Your rule description',
125
+ category: 'Best Practices',
126
+ recommended: false,
127
+ },
128
+ schema: [], // JSON schema for rule options
129
+ messages: {
130
+ // Define error messages here
131
+ },
132
+ },
133
+ create(context) {
134
+ // Your rule implementation
135
+ return {
136
+ // AST node visitors
137
+ }
138
+ },
139
+ }
140
+
141
+ export default rule
142
+ ```
143
+
144
+ 2. **Add tests** in `src/rules/your-rule-name.spec.ts`:
145
+ ```typescript
146
+ import { RuleTester } from '@typescript-eslint/rule-tester'
147
+ import rule from './your-rule-name'
148
+
149
+ const ruleTester = new RuleTester({
150
+ parser: '@angular-eslint/template-parser',
151
+ })
152
+
153
+ ruleTester.run('your-rule-name', rule, {
154
+ valid: [
155
+ // Test cases that should pass
156
+ ],
157
+ invalid: [
158
+ // Test cases that should fail
159
+ ],
160
+ })
161
+ ```
162
+
163
+ 3. **Export the rule** in `src/rules/index.ts`:
164
+ ```typescript
165
+ import yourRuleName from './your-rule-name'
166
+
167
+ export const rules = {
168
+ 'require-data-testid': requireDataTestId,
169
+ 'your-rule-name': yourRuleName,
170
+ }
171
+ ```
172
+
173
+ 4. **Add to recommended config** (optional) in `src/configs/recommended.ts`:
174
+ ```typescript
175
+ rules: {
176
+ 'tgo/require-data-testid': 'warn',
177
+ 'tgo/your-rule-name': 'error', // or 'warn'
178
+ }
179
+ ```
180
+
181
+ 5. **Document the rule** in `src/rules/your-rule-name.md`:
182
+ - Describe what the rule does
183
+ - Provide configuration options
184
+ - Show correct and incorrect code examples
185
+ - Explain the rationale
186
+
187
+ 6. **Update this README** by adding the new rule to the rules table above
188
+
189
+ 7. **Test your changes**:
190
+ ```bash
191
+ nx test tgo-linting
192
+ nx build tgo-linting
193
+ ```
101
194
 
102
195
  ## Development
103
196
 
package/package.json CHANGED
@@ -1,42 +1,40 @@
1
1
  {
2
2
  "name": "@testgorilla/tgo-linting",
3
- "version": "1.0.0",
4
- "description": "Linting rules and code quality standards for TestGorilla projects",
5
- "keywords": [
6
- "eslint",
7
- "eslintplugin",
8
- "eslint-plugin",
9
- "testgorilla",
10
- "angular",
11
- "testing",
12
- "linting",
13
- "code-quality",
14
- "accessibility"
15
- ],
16
- "author": "TestGorilla",
17
- "license": "PROPRIETARY",
18
- "main": "./src/index.js",
19
- "types": "./src/index.d.ts",
20
- "files": [
21
- "**/*"
22
- ],
23
- "sideEffects": false,
24
- "private": false,
25
- "publishConfig": {
26
- "access": "public",
27
- "registry": "https://registry.npmjs.org/"
28
- },
3
+ "version": "1.0.2",
29
4
  "peerDependencies": {
5
+ "@angular-eslint/template-parser": ">= 17.0.0 < 20.0.0",
30
6
  "eslint": "^8 || ^9",
31
7
  "tslib": "^2.0.0"
32
8
  },
33
9
  "dependencies": {
34
10
  "@typescript-eslint/utils": "^8.54.0"
35
11
  },
12
+ "sideEffects": false,
13
+ "private": false,
14
+ "license": "PROPRIETARY",
15
+ "publishConfig": {
16
+ "access": "public",
17
+ "registry": "https://registry.npmjs.org/"
18
+ },
36
19
  "displayName": "TGO Linting",
37
- "repository": {
38
- "type": "git",
39
- "url": "https://github.com/testgorilla/tgo-fe-libraries"
20
+ "description": "Linting rules and code quality standards for TestGorilla projects",
21
+ "author": "TestGorilla",
22
+ "main": "./src/index.js",
23
+ "types": "./src/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./src/index.js",
27
+ "require": "./src/index.js",
28
+ "types": "./src/index.d.ts"
29
+ },
30
+ "./legacy": {
31
+ "import": "./src/configs/legacy.js",
32
+ "require": "./src/configs/legacy.js",
33
+ "types": "./src/configs/legacy.d.ts"
34
+ }
40
35
  },
36
+ "files": [
37
+ "**/*"
38
+ ],
41
39
  "type": "commonjs"
42
40
  }
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ plugins: string[];
3
+ rules: {
4
+ 'tgo/require-data-testid': string;
5
+ };
6
+ };
7
+ export default _default;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ plugins: ['tgo'],
5
+ rules: {
6
+ 'tgo/require-data-testid': 'warn',
7
+ },
8
+ };
9
+ //# sourceMappingURL=legacy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../../../../packages/tgo-linting/src/configs/legacy.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb,OAAO,EAAE,CAAC,KAAK,CAAC;IAChB,KAAK,EAAE;QACL,yBAAyB,EAAE,MAAM;KAClC;CACF,CAAA","sourcesContent":["export default {\n plugins: ['tgo'],\n rules: {\n 'tgo/require-data-testid': 'warn',\n },\n}\n"]}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  plugins: ['tgo'],
5
5
  rules: {
6
- 'tgo/require-data-testid': 'error',
6
+ 'tgo/require-data-testid': 'warn',
7
7
  },
8
8
  };
9
9
  //# sourceMappingURL=recommended.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../../../../packages/tgo-linting/src/configs/recommended.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb,OAAO,EAAE,CAAC,KAAK,CAAC;IAChB,KAAK,EAAE;QACL,yBAAyB,EAAE,OAAO;KACnC;CACF,CAAA","sourcesContent":["export default {\n plugins: ['tgo'],\n rules: {\n 'tgo/require-data-testid': 'error',\n },\n}"]}
1
+ {"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../../../../packages/tgo-linting/src/configs/recommended.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb,OAAO,EAAE,CAAC,KAAK,CAAC;IAChB,KAAK,EAAE;QACL,yBAAyB,EAAE,MAAM;KAClC;CACF,CAAA","sourcesContent":["export default {\n plugins: ['tgo'],\n rules: {\n 'tgo/require-data-testid': 'warn',\n },\n}"]}
package/src/index.d.ts CHANGED
@@ -1,4 +1,11 @@
1
- declare const _default: {
1
+ import { rules } from './rules';
2
+ import recommended from './configs/recommended';
3
+ import legacy from './configs/legacy';
4
+ declare const plugin: {
5
+ meta: {
6
+ name: string;
7
+ version: string;
8
+ };
2
9
  rules: {
3
10
  'require-data-testid': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingTestId", [{
4
11
  tags?: string[];
@@ -13,4 +20,5 @@ declare const _default: {
13
20
  };
14
21
  };
15
22
  };
16
- export = _default;
23
+ export default plugin;
24
+ export { rules, recommended, legacy };
package/src/index.js CHANGED
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.legacy = exports.recommended = exports.rules = void 0;
2
4
  const rules_1 = require("./rules");
5
+ Object.defineProperty(exports, "rules", { enumerable: true, get: function () { return rules_1.rules; } });
3
6
  const recommended_1 = require("./configs/recommended");
4
- module.exports = {
7
+ exports.recommended = recommended_1.default;
8
+ const legacy_1 = require("./configs/legacy");
9
+ exports.legacy = legacy_1.default;
10
+ const plugin = {
11
+ meta: {
12
+ name: '@testgorilla/tgo-linting',
13
+ version: '1.0.0',
14
+ },
5
15
  rules: rules_1.rules,
6
16
  configs: {
7
17
  recommended: recommended_1.default,
8
18
  },
9
19
  };
20
+ // Default export for ESM and CommonJS compatibility
21
+ exports.default = plugin;
10
22
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/tgo-linting/src/index.ts"],"names":[],"mappings":";AAAA,mCAA+B;AAC/B,uDAA+C;AAE/C,iBAAS;IACP,KAAK,EAAL,aAAK;IACL,OAAO,EAAE;QACP,WAAW,EAAX,qBAAW;KACZ;CACF,CAAA","sourcesContent":["import { rules } from './rules'\nimport recommended from './configs/recommended'\n\nexport = {\n rules,\n configs: {\n recommended,\n },\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/tgo-linting/src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAmBtB,sFAnBA,aAAK,OAmBA;AAlBd,uDAA+C;AAkB/B,sBAlBT,qBAAW,CAkBS;AAjB3B,6CAAqC;AAiBR,iBAjBtB,gBAAM,CAiBsB;AAfnC,MAAM,MAAM,GAAG;IACb,IAAI,EAAE;QACJ,IAAI,EAAE,0BAA0B;QAChC,OAAO,EAAE,OAAO;KACjB;IACD,KAAK,EAAL,aAAK;IACL,OAAO,EAAE;QACP,WAAW,EAAX,qBAAW;KACZ;CACF,CAAA;AAED,oDAAoD;AACpD,kBAAe,MAAM,CAAA","sourcesContent":["import { rules } from './rules'\nimport recommended from './configs/recommended'\nimport legacy from './configs/legacy'\n\nconst plugin = {\n meta: {\n name: '@testgorilla/tgo-linting',\n version: '1.0.0',\n },\n rules,\n configs: {\n recommended,\n },\n}\n\n// Default export for ESM and CommonJS compatibility\nexport default plugin\n\n// Named exports for specific use cases\nexport { rules, recommended, legacy }\n"]}