@webpieces/dev-config 0.0.0-dev → 0.2.17

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.
@@ -2,7 +2,6 @@
2
2
  * Tests for catch-error-pattern ESLint rule
3
3
  */
4
4
 
5
- /* eslint-disable @webpieces/catch-error-pattern */
6
5
  import { RuleTester } from 'eslint';
7
6
  import rule from '../rules/catch-error-pattern';
8
7
 
@@ -7,8 +7,6 @@
7
7
  declare const _default: {
8
8
  rules: {
9
9
  'catch-error-pattern': import("eslint").Rule.RuleModule;
10
- 'max-method-lines': import("eslint").Rule.RuleModule;
11
- 'max-file-lines': import("eslint").Rule.RuleModule;
12
10
  };
13
11
  };
14
12
  export = _default;
@@ -7,13 +7,9 @@
7
7
  */
8
8
  const tslib_1 = require("tslib");
9
9
  const catch_error_pattern_1 = tslib_1.__importDefault(require("./rules/catch-error-pattern"));
10
- const max_method_lines_1 = tslib_1.__importDefault(require("./rules/max-method-lines"));
11
- const max_file_lines_1 = tslib_1.__importDefault(require("./rules/max-file-lines"));
12
10
  module.exports = {
13
11
  rules: {
14
12
  'catch-error-pattern': catch_error_pattern_1.default,
15
- 'max-method-lines': max_method_lines_1.default,
16
- 'max-file-lines': max_file_lines_1.default,
17
13
  },
18
14
  };
19
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/dev-config/eslint-plugin/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,8FAA4D;AAC5D,wFAAsD;AACtD,oFAAkD;AAElD,iBAAS;IACL,KAAK,EAAE;QACH,qBAAqB,EAAE,6BAAiB;QACxC,kBAAkB,EAAE,0BAAc;QAClC,gBAAgB,EAAE,wBAAY;KACjC;CACJ,CAAC","sourcesContent":["/**\n * ESLint plugin for WebPieces\n * Provides rules for enforcing WebPieces code patterns\n *\n * This plugin is automatically included in @webpieces/dev-config\n */\n\nimport catchErrorPattern from './rules/catch-error-pattern';\nimport maxMethodLines from './rules/max-method-lines';\nimport maxFileLines from './rules/max-file-lines';\n\nexport = {\n rules: {\n 'catch-error-pattern': catchErrorPattern,\n 'max-method-lines': maxMethodLines,\n 'max-file-lines': maxFileLines,\n },\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/dev-config/eslint-plugin/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,8FAA4D;AAE5D,iBAAS;IACL,KAAK,EAAE;QACH,qBAAqB,EAAE,6BAAiB;KAC3C;CACJ,CAAC","sourcesContent":["/**\n * ESLint plugin for WebPieces\n * Provides rules for enforcing WebPieces code patterns\n *\n * This plugin is automatically included in @webpieces/dev-config\n */\n\nimport catchErrorPattern from './rules/catch-error-pattern';\n\nexport = {\n rules: {\n 'catch-error-pattern': catchErrorPattern,\n },\n};\n"]}
@@ -6,13 +6,9 @@
6
6
  */
7
7
 
8
8
  import catchErrorPattern from './rules/catch-error-pattern';
9
- import maxMethodLines from './rules/max-method-lines';
10
- import maxFileLines from './rules/max-file-lines';
11
9
 
12
10
  export = {
13
11
  rules: {
14
12
  'catch-error-pattern': catchErrorPattern,
15
- 'max-method-lines': maxMethodLines,
16
- 'max-file-lines': maxFileLines,
17
13
  },
18
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/dev-config",
3
- "version": "0.0.0-dev",
3
+ "version": "0.2.17",
4
4
  "description": "Development configuration, scripts, and patterns for WebPieces projects",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -27,10 +27,6 @@
27
27
  "peerDependencies": {
28
28
  "eslint": ">=8.0.0"
29
29
  },
30
- "devDependencies": {
31
- "@types/eslint": "^9.6.1",
32
- "eslint": "^9.39.1"
33
- },
34
30
  "keywords": [
35
31
  "webpieces",
36
32
  "config",
@@ -1,195 +0,0 @@
1
- /**
2
- * Tests for max-file-lines ESLint rule
3
- */
4
-
5
- import { RuleTester } from 'eslint';
6
- import rule from '../rules/max-file-lines';
7
- import * as fs from 'fs';
8
- import * as path from 'path';
9
-
10
- // Use require to load parser at runtime (avoids TypeScript import issues)
11
- const tsParser = require('@typescript-eslint/parser');
12
-
13
- const ruleTester = new RuleTester({
14
- languageOptions: {
15
- parser: tsParser,
16
- parserOptions: {
17
- ecmaVersion: 2020,
18
- sourceType: 'module',
19
- },
20
- },
21
- });
22
-
23
- ruleTester.run('max-file-lines', rule, {
24
- valid: [
25
- // Short file (well under limit)
26
- {
27
- code: `function shortFunc() {
28
- return 42;
29
- }`,
30
- },
31
- // File with exactly 700 lines (default limit)
32
- {
33
- code: Array(700)
34
- .fill(0)
35
- .map((_, i) => `const line${i} = ${i};`)
36
- .join('\n'),
37
- },
38
- // File with 699 lines (just under default limit)
39
- {
40
- code: Array(699)
41
- .fill(0)
42
- .map((_, i) => `const line${i} = ${i};`)
43
- .join('\n'),
44
- },
45
- // Custom limit: 10 lines
46
- {
47
- code: `function shortFunc() {
48
- const a = 1;
49
- const b = 2;
50
- const c = 3;
51
- const d = 4;
52
- const e = 5;
53
- return a + b + c + d + e;
54
- }`,
55
- options: [{ max: 10 }],
56
- },
57
- // Empty file
58
- {
59
- code: '',
60
- },
61
- // File with comments and blank lines (all count)
62
- {
63
- code: `// Comment line 1
64
- // Comment line 2
65
-
66
- function func() {
67
- return 42;
68
- }
69
-
70
- // Another comment`,
71
- options: [{ max: 10 }],
72
- },
73
- ],
74
-
75
- invalid: [
76
- // File with 701 lines (exceeds default limit)
77
- {
78
- code: Array(701)
79
- .fill(0)
80
- .map((_, i) => `const line${i} = ${i};`)
81
- .join('\n'),
82
- errors: [
83
- {
84
- messageId: 'tooLong',
85
- data: { actual: '701', max: '700' },
86
- },
87
- ],
88
- },
89
- // File with 1000 lines (way over limit)
90
- {
91
- code: Array(1000)
92
- .fill(0)
93
- .map((_, i) => `const line${i} = ${i};`)
94
- .join('\n'),
95
- errors: [
96
- {
97
- messageId: 'tooLong',
98
- data: { actual: '1000', max: '700' },
99
- },
100
- ],
101
- },
102
- // Custom limit: exceed 5 lines
103
- {
104
- code: `function func() {
105
- const a = 1;
106
- const b = 2;
107
- const c = 3;
108
- const d = 4;
109
- return a + b + c + d;
110
- }`,
111
- options: [{ max: 5 }],
112
- errors: [
113
- {
114
- messageId: 'tooLong',
115
- data: { actual: '7', max: '5' },
116
- },
117
- ],
118
- },
119
- // Custom limit: exceed 100 lines
120
- {
121
- code: Array(101)
122
- .fill(0)
123
- .map((_, i) => `const line${i} = ${i};`)
124
- .join('\n'),
125
- options: [{ max: 100 }],
126
- errors: [
127
- {
128
- messageId: 'tooLong',
129
- data: { actual: '101', max: '100' },
130
- },
131
- ],
132
- },
133
- // File with blank lines and comments (all lines count)
134
- {
135
- code: `// Line 1
136
- // Line 2
137
- // Line 3
138
-
139
- function func() {
140
- return 42;
141
- }
142
-
143
- // Line 9
144
- // Line 10
145
- // Line 11`,
146
- options: [{ max: 10 }],
147
- errors: [
148
- {
149
- messageId: 'tooLong',
150
- data: { actual: '11', max: '10' },
151
- },
152
- ],
153
- },
154
- ],
155
- });
156
-
157
- console.log('✅ All max-file-lines rule tests passed!');
158
-
159
- // Test documentation file creation
160
- const docPath = path.join(process.cwd(), 'tmp', 'webpieces', 'webpieces.filesize.md');
161
-
162
- // Run a test that triggers violation
163
- try {
164
- ruleTester.run('max-file-lines-doc-test', rule, {
165
- valid: [],
166
- invalid: [
167
- {
168
- code: Array(800)
169
- .fill(0)
170
- .map((_, i) => `const line${i} = ${i};`)
171
- .join('\n'),
172
- errors: [{ messageId: 'tooLong' }],
173
- },
174
- ],
175
- });
176
- } catch (err: any) {
177
- //const error = toError(err);
178
- // Test may fail, but file should be created
179
- }
180
-
181
- // Verify file was created
182
- if (!fs.existsSync(docPath)) {
183
- throw new Error('Documentation file was not created at ' + docPath);
184
- }
185
-
186
- // Verify content has AI directive
187
- const content = fs.readFileSync(docPath, 'utf-8');
188
- if (!content.includes('READ THIS FILE to fix files that are too long')) {
189
- throw new Error('Documentation file missing AI directive');
190
- }
191
- if (!content.includes('SINGLE COHESIVE UNIT')) {
192
- throw new Error('Documentation file missing single cohesive unit principle');
193
- }
194
-
195
- console.log('✅ Documentation file creation test passed!');
@@ -1,246 +0,0 @@
1
- /**
2
- * Tests for max-method-lines ESLint rule
3
- */
4
-
5
- import { RuleTester } from 'eslint';
6
- import rule from '../rules/max-method-lines';
7
- import * as fs from 'fs';
8
- import * as path from 'path';
9
-
10
- // Use require to load parser at runtime (avoids TypeScript import issues)
11
- const tsParser = require('@typescript-eslint/parser');
12
-
13
- const ruleTester = new RuleTester({
14
- languageOptions: {
15
- parser: tsParser,
16
- parserOptions: {
17
- ecmaVersion: 2020,
18
- sourceType: 'module',
19
- },
20
- },
21
- });
22
-
23
- ruleTester.run('max-method-lines', rule, {
24
- valid: [
25
- // Short function (well under limit)
26
- {
27
- code: `function shortFunc() {
28
- return 42;
29
- }`,
30
- },
31
- // Function with exactly 70 lines (default limit)
32
- {
33
- code: `function exactlySeventyLines() {
34
- ${Array(68)
35
- .fill(0)
36
- .map((_, i) => ` const line${i} = ${i};`)
37
- .join('\n')}
38
- }`,
39
- },
40
- // Function with 69 lines (just under default limit)
41
- {
42
- code: `function sixtyNineLines() {
43
- ${Array(67)
44
- .fill(0)
45
- .map((_, i) => ` const line${i} = ${i};`)
46
- .join('\n')}
47
- }`,
48
- },
49
- // Custom limit: 10 lines
50
- {
51
- code: `function shortFunc() {
52
- const a = 1;
53
- const b = 2;
54
- const c = 3;
55
- const d = 4;
56
- const e = 5;
57
- const f = 6;
58
- const g = 7;
59
- return a + b + c + d + e + f + g;
60
- }`,
61
- options: [{ max: 10 }],
62
- },
63
- // Arrow function under limit
64
- {
65
- code: `const shortArrow = () => {
66
- return 42;
67
- };`,
68
- },
69
- // Method definition under limit
70
- {
71
- code: `class MyClass {
72
- shortMethod() {
73
- return 42;
74
- }
75
- }`,
76
- },
77
- // Function expression under limit
78
- {
79
- code: `const func = function() {
80
- return 42;
81
- };`,
82
- },
83
- ],
84
-
85
- invalid: [
86
- // Function with 71 lines (exceeds default limit)
87
- {
88
- code: `function tooLong() {
89
- ${Array(69)
90
- .fill(0)
91
- .map((_, i) => ` const line${i} = ${i};`)
92
- .join('\n')}
93
- }`,
94
- errors: [
95
- {
96
- messageId: 'tooLong',
97
- data: { name: 'tooLong', actual: '71', max: '70' },
98
- },
99
- ],
100
- },
101
- // Function with 100 lines (way over limit)
102
- {
103
- code: `function wayTooLong() {
104
- ${Array(98)
105
- .fill(0)
106
- .map((_, i) => ` const line${i} = ${i};`)
107
- .join('\n')}
108
- }`,
109
- errors: [
110
- {
111
- messageId: 'tooLong',
112
- data: { name: 'wayTooLong', actual: '100', max: '70' },
113
- },
114
- ],
115
- },
116
- // Custom limit: exceed 5 lines
117
- {
118
- code: `function tooLongForCustom() {
119
- const a = 1;
120
- const b = 2;
121
- const c = 3;
122
- const d = 4;
123
- return a + b + c + d;
124
- }`,
125
- options: [{ max: 5 }],
126
- errors: [
127
- {
128
- messageId: 'tooLong',
129
- data: { name: 'tooLongForCustom', actual: '7', max: '5' },
130
- },
131
- ],
132
- },
133
- // Arrow function exceeding limit
134
- {
135
- code: `const tooLongArrow = () => {
136
- ${Array(69)
137
- .fill(0)
138
- .map((_, i) => ` const line${i} = ${i};`)
139
- .join('\n')}
140
- };`,
141
- errors: [
142
- {
143
- messageId: 'tooLong',
144
- data: { name: 'anonymous', actual: '71', max: '70' },
145
- },
146
- ],
147
- },
148
- // Method definition exceeding limit
149
- {
150
- code: `class MyClass {
151
- tooLongMethod() {
152
- ${Array(69)
153
- .fill(0)
154
- .map((_, i) => ` const line${i} = ${i};`)
155
- .join('\n')}
156
- }
157
- }`,
158
- errors: [
159
- {
160
- messageId: 'tooLong',
161
- data: { name: 'tooLongMethod', actual: '71', max: '70' },
162
- },
163
- ],
164
- },
165
- // Function expression exceeding limit
166
- {
167
- code: `const func = function tooLongFunc() {
168
- ${Array(69)
169
- .fill(0)
170
- .map((_, i) => ` const line${i} = ${i};`)
171
- .join('\n')}
172
- };`,
173
- errors: [
174
- {
175
- messageId: 'tooLong',
176
- data: { name: 'tooLongFunc', actual: '71', max: '70' },
177
- },
178
- ],
179
- },
180
- // Multiple functions, one exceeds limit
181
- {
182
- code: `function shortFunc() {
183
- return 42;
184
- }
185
-
186
- function tooLong() {
187
- ${Array(69)
188
- .fill(0)
189
- .map((_, i) => ` const line${i} = ${i};`)
190
- .join('\n')}
191
- }
192
-
193
- function anotherShort() {
194
- return 24;
195
- }`,
196
- errors: [
197
- {
198
- messageId: 'tooLong',
199
- data: { name: 'tooLong', actual: '71', max: '70' },
200
- },
201
- ],
202
- },
203
- ],
204
- });
205
-
206
- console.log('✅ All max-method-lines rule tests passed!');
207
-
208
- // Test documentation file creation
209
- const docPath = path.join(process.cwd(), 'tmp', 'webpieces', 'webpieces.methods.md');
210
-
211
- // Run a test that triggers violation (will create doc file)
212
- try {
213
- ruleTester.run('max-method-lines-doc-test', rule, {
214
- valid: [],
215
- invalid: [
216
- {
217
- code: `function veryLongMethod() {
218
- ${Array(100)
219
- .fill(0)
220
- .map((_, i) => ` const line${i} = ${i};`)
221
- .join('\n')}
222
- }`,
223
- errors: [{ messageId: 'tooLong' }],
224
- },
225
- ],
226
- });
227
- } catch (err: any) {
228
- //const error = toError(err);
229
- // Test may fail due to too many errors, but file should be created
230
- }
231
-
232
- // Verify file was created
233
- if (!fs.existsSync(docPath)) {
234
- throw new Error('Documentation file was not created at ' + docPath);
235
- }
236
-
237
- // Verify content has AI directive
238
- const content = fs.readFileSync(docPath, 'utf-8');
239
- if (!content.includes('READ THIS FILE to fix methods that are too long')) {
240
- throw new Error('Documentation file missing AI directive');
241
- }
242
- if (!content.includes('TABLE OF CONTENTS')) {
243
- throw new Error('Documentation file missing table of contents principle');
244
- }
245
-
246
- console.log('✅ Documentation file creation test passed!');
@@ -1,12 +0,0 @@
1
- /**
2
- * ESLint rule to enforce maximum file length
3
- *
4
- * Enforces a configurable maximum line count for files.
5
- * Default: 700 lines
6
- *
7
- * Configuration:
8
- * '@webpieces/max-file-lines': ['error', { max: 700 }]
9
- */
10
- import type { Rule } from 'eslint';
11
- declare const rule: Rule.RuleModule;
12
- export = rule;