eslint-plugin-ai-rules 0.1.0
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/LICENSE +21 -0
- package/README.md +313 -0
- package/dist/index.cjs +336 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +295 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 eslint-plugin-ai-rules
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# eslint-plugin-ai-rules
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/eslint-plugin-ai-rules)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](package.json)
|
|
6
|
+
[](https://eslint.org)
|
|
7
|
+
|
|
8
|
+
Flat-config only ESLint plugin that bundles useful rules for AI-generated code. Ships a `recommended` preset with all rules enabled as `error` — zero config for consumers.
|
|
9
|
+
|
|
10
|
+
> **ESLint 9+ only.** Uses flat config (`eslint.config.{ts,js}`) and `eslint/config` `defineConfig`. No legacy `.eslintrc` support.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **AI Rules rules** — catches typical AI drift: wrong filename casing, unsorted/multiline imports
|
|
15
|
+
- **Bundled preset** — `aiRules.configs.recommended` enables custom + `import-x`, `@stylistic`, `typescript-eslint` rules out of the box
|
|
16
|
+
- **Autofix** — `sort-imports` and `no-multiline-imports` are `fixable: code` (`eslint --fix`)
|
|
17
|
+
- **Dual build** — `dist/index.js` (ESM) + `dist/index.cjs` (CJS) via `tsup`, single-file bundle, `type: module`
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
- Node `>=18` (`package.json` `engines`)
|
|
22
|
+
- ESLint `^8.57.0 || ^9.0.0` (peer) — flat config requires ESLint 9
|
|
23
|
+
- TypeScript `>=5.0.0` (peer)
|
|
24
|
+
- `jiti` if you use `eslint.config.ts` (ESLint loads TS config via `jiti`)
|
|
25
|
+
|
|
26
|
+
`@eslint/js`, `eslint-plugin-import-x`, `@stylistic/eslint-plugin`, `typescript-eslint`, `globals` are already `dependencies` — you don't need to install them.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# npm
|
|
32
|
+
npm i -D eslint-plugin-ai-rules eslint typescript
|
|
33
|
+
|
|
34
|
+
# yarn
|
|
35
|
+
yarn add -D eslint-plugin-ai-rules eslint typescript
|
|
36
|
+
|
|
37
|
+
# pnpm
|
|
38
|
+
pnpm add -D eslint-plugin-ai-rules eslint typescript
|
|
39
|
+
|
|
40
|
+
# bun
|
|
41
|
+
bun add -d eslint-plugin-ai-rules eslint typescript
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
> `jiti` is required only for `eslint.config.ts`. Install it as dev dep if you use TS config:
|
|
45
|
+
> ```bash
|
|
46
|
+
> npm i -D jiti
|
|
47
|
+
> ```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
### `eslint.config.ts` (recommended)
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import aiRules from 'eslint-plugin-ai-rules'
|
|
55
|
+
|
|
56
|
+
export default [
|
|
57
|
+
...aiRules.configs.recommended,
|
|
58
|
+
]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `eslint.config.js` / `eslint.config.mjs`
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import aiRules from 'eslint-plugin-ai-rules'
|
|
65
|
+
|
|
66
|
+
export default [
|
|
67
|
+
...aiRules.configs.recommended,
|
|
68
|
+
]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### With overrides
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import aiRules from 'eslint-plugin-ai-rules'
|
|
75
|
+
import { defineConfig } from 'eslint/config'
|
|
76
|
+
|
|
77
|
+
export default defineConfig([
|
|
78
|
+
...aiRules.configs.recommended,
|
|
79
|
+
{
|
|
80
|
+
// turn off filename check for tests or generated code
|
|
81
|
+
files: ['**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}', 'scripts/**/*'],
|
|
82
|
+
rules: {
|
|
83
|
+
'ai-rules/filename-pascal-case': 'off',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
// or disable a bundled rule
|
|
88
|
+
rules: {
|
|
89
|
+
'@stylistic/semi': 'off',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
])
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Run:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npx eslint .
|
|
99
|
+
npx eslint --fix . # autofix for sort-imports / no-multiline-imports
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
### `recommended` preset
|
|
105
|
+
|
|
106
|
+
`src/configs/recommended.ts` exports `defineConfig([...])` with:
|
|
107
|
+
|
|
108
|
+
- `globalIgnores(['dist', 'src/services/generated', 'scripts/types'])`
|
|
109
|
+
- `files: ['**/*.{ts,tsx}']` — `extends: [js.configs.recommended, tseslint.configs.recommended]`, `languageOptions.globals: globals.browser`, `import-x/resolver-next` with `extensions: ['.ts','.tsx','.d.ts','.js','.jsx']`
|
|
110
|
+
- `plugins: { '@stylistic': stylistic, 'import-x': importX, 'ai-rules': plugin }`
|
|
111
|
+
- Rules (all `error` unless noted):
|
|
112
|
+
|
|
113
|
+
| Rule | Default | Notes |
|
|
114
|
+
|------|---------|-------|
|
|
115
|
+
| `ai-rules/filename-pascal-case` | `error` | `src/` + `scripts/` only. See below |
|
|
116
|
+
| `ai-rules/sort-imports` | `error` | Groups + length desc, collapses multiline |
|
|
117
|
+
| `ai-rules/no-multiline-imports` | `error` | Single-line imports |
|
|
118
|
+
| `import-x/no-duplicates` | `error` | |
|
|
119
|
+
| `import-x/no-default-export` | `off` | |
|
|
120
|
+
| `max-len` | `off` | |
|
|
121
|
+
| `@stylistic/semi` | `['error','never']` | No semicolons |
|
|
122
|
+
| `@typescript-eslint/consistent-type-imports` | `['error',{prefer:'type-imports'}]` | |
|
|
123
|
+
| `@typescript-eslint/no-unused-vars` | `['error',{argsIgnorePattern:'^_',varsIgnorePattern:'^_'}]` | |
|
|
124
|
+
| `@typescript-eslint/naming-convention` | `['error', {interface:'PascalCase' prefix I}, {typeAlias:'PascalCase' prefix T}]` | Second override disables it for `**/*.d.ts` + `scripts/**/*` |
|
|
125
|
+
|
|
126
|
+
Second config entry: `files: ['**/*.d.ts','scripts/**/*']` → `naming-convention: off`.
|
|
127
|
+
|
|
128
|
+
### Custom setup (without `recommended`)
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { plugin } from 'eslint-plugin-ai-rules'
|
|
132
|
+
import { defineConfig } from 'eslint/config'
|
|
133
|
+
|
|
134
|
+
export default defineConfig([
|
|
135
|
+
{
|
|
136
|
+
files: ['**/*.{ts,tsx}'],
|
|
137
|
+
plugins: { 'ai-rules': plugin },
|
|
138
|
+
rules: {
|
|
139
|
+
'ai-rules/sort-imports': 'error',
|
|
140
|
+
'ai-rules/no-multiline-imports': 'warn',
|
|
141
|
+
'ai-rules/filename-pascal-case': 'off',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
])
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
You can also import rules individually:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { filenamePascalCase, sortImports, noMultilineImports } from 'eslint-plugin-ai-rules'
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Rules
|
|
154
|
+
|
|
155
|
+
Brief overview. See source in `src/rules/` for full logic.
|
|
156
|
+
|
|
157
|
+
### `ai-rules/filename-pascal-case`
|
|
158
|
+
|
|
159
|
+
Enforces `PascalCase` for files under `src/` and `scripts/`.
|
|
160
|
+
|
|
161
|
+
- **Type:** `suggestion`, no autofix, `messageId: invalid`
|
|
162
|
+
- **Ignores:** `index.{ts,tsx,js,jsx}`, `*.d.ts`, `*.css`
|
|
163
|
+
- **Checks:** `path.basename` normalized via `path.sep`, `getPhysicalFilename()` / `getCwd()` aware, `^[A-Z][a-zA-Z0-9]*$`, `kebab/snake -> PascalCase` conversion
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
// src/my-component.ts ❌ File name "my-component.ts" must be in PascalCase. Rename to "MyComponent.ts".
|
|
167
|
+
// src/MyComponent.ts ✅
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
To disable internally (as this repo does in `eslint.config.ts`):
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { defineConfig } from 'eslint/config'
|
|
174
|
+
import { recommended } from './src/configs/recommended'
|
|
175
|
+
|
|
176
|
+
export default defineConfig([
|
|
177
|
+
...recommended,
|
|
178
|
+
{ files: ['src/**/*'], rules: { 'ai-rules/filename-pascal-case': 'off' } },
|
|
179
|
+
])
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### `ai-rules/no-multiline-imports`
|
|
183
|
+
|
|
184
|
+
Disallows multiline `ImportDeclaration`.
|
|
185
|
+
|
|
186
|
+
- **Type:** `layout`, `fixable: code`, `messageId: multilineImport`
|
|
187
|
+
- **Fix:** collapses `{`, `}`, `,` and whitespace to single line: `import { b, a } from 'lodash'`
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
// ❌
|
|
191
|
+
import {
|
|
192
|
+
b,
|
|
193
|
+
a
|
|
194
|
+
} from 'lodash'
|
|
195
|
+
|
|
196
|
+
// ✅ after --fix
|
|
197
|
+
import { b, a } from 'lodash'
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Note: `ai-rules/sort-imports` also collapses multiline; both fixers may run, but `sort-imports` handles the full `Program` sort.
|
|
201
|
+
|
|
202
|
+
### `ai-rules/sort-imports`
|
|
203
|
+
|
|
204
|
+
Sorts imports by group and line-length descending, collapsing multiline imports.
|
|
205
|
+
|
|
206
|
+
- **Type:** `layout`, `fixable: code` (`Program` fixer), `messageId: sortRequired`
|
|
207
|
+
- **Groups (in order, each separated by one blank line):**
|
|
208
|
+
1. Directives (`'use client'`, `'use server'`, `'use strict'`)
|
|
209
|
+
2. External (`react` first, then other externals sorted by `line.length` desc → `localeCompare`)
|
|
210
|
+
3. Internal (`.`, `@/` sorted same)
|
|
211
|
+
4. Re-exports (`export { ... } from`, `export * from` sorted same)
|
|
212
|
+
- **Rest:** code after imports, joined with `\n\n\n` (two blank lines between imports and code)
|
|
213
|
+
- **Directives:** preserved at top while `canAcceptDirectives` is true
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
// ❌ before --fix
|
|
217
|
+
import { local } from './local'
|
|
218
|
+
import { a } from 'lodash'
|
|
219
|
+
import React from 'react'
|
|
220
|
+
|
|
221
|
+
// ✅ after --fix
|
|
222
|
+
import React from 'react'
|
|
223
|
+
import { a } from 'lodash'
|
|
224
|
+
|
|
225
|
+
import { local } from './local'
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Supports side-effect `import 'polyfill'`, `import type`, `export * from`, `export { ... } from`.
|
|
229
|
+
|
|
230
|
+
## TypeScript
|
|
231
|
+
|
|
232
|
+
Plugin itself uses `module: ESNext` + `moduleResolution: bundler` (`tsconfig.json`) and **no `.js` extensions** in source imports (e.g., `from './plugin'`). Output is bundled to single `dist/index.js` via `tsup`, so consumers don't need to handle internal paths. For your project, any TS config works; the preset sets `languageOptions.globals: globals.browser` and `import-x/resolver-next`.
|
|
233
|
+
|
|
234
|
+
## Troubleshooting
|
|
235
|
+
|
|
236
|
+
**`jiti` is required for loading TypeScript configuration files**
|
|
237
|
+
```
|
|
238
|
+
Error: The 'jiti' library is required for loading TypeScript configuration files.
|
|
239
|
+
```
|
|
240
|
+
Fix: `npm i -D jiti`
|
|
241
|
+
|
|
242
|
+
**File ignored because outside of base path**
|
|
243
|
+
You passed an absolute path outside the config's `basePath`. Run `npx eslint .` from project root or use `npx eslint --no-config-lookup -c ./eslint.config.js ./src/file.ts` with correct cwd.
|
|
244
|
+
|
|
245
|
+
**Flat config only**
|
|
246
|
+
This plugin exports `defineConfig` arrays. It does not support legacy `.eslintrc`. Use `eslint.config.{js,ts}`.
|
|
247
|
+
|
|
248
|
+
**Filename rule too strict for tests**
|
|
249
|
+
Override as shown in Quick Start: disable `ai-rules/filename-pascal-case` for `**/*.test.*`, `**/*.spec.*`, or your own `src/__fixtures__`.
|
|
250
|
+
|
|
251
|
+
## Development
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
git clone <repo>
|
|
255
|
+
cd eslint-ai-guard
|
|
256
|
+
npm install
|
|
257
|
+
|
|
258
|
+
npm run typecheck # tsc --noEmit
|
|
259
|
+
npm run lint # eslint .
|
|
260
|
+
npm run lint -- --fix
|
|
261
|
+
npm run build # tsup -> dist/index.js + dist/index.cjs + dist/index.d.ts
|
|
262
|
+
npm run dev # tsup --watch
|
|
263
|
+
npm pack --dry-run # verify files: dist only
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Project structure
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
eslint-ai-guard/ # package: eslint-plugin-ai-rules
|
|
270
|
+
├── src/
|
|
271
|
+
│ ├── index.ts # re-exports plugin + recommended
|
|
272
|
+
│ ├── plugin.ts # plugin.meta + rules
|
|
273
|
+
│ ├── configs/
|
|
274
|
+
│ │ ├── recommended.ts # defineConfig preset (bundled rules)
|
|
275
|
+
│ │ └── index.ts
|
|
276
|
+
│ └── rules/
|
|
277
|
+
│ ├── FilenamePascalCase.ts
|
|
278
|
+
│ ├── NoMultilineImports.ts
|
|
279
|
+
│ ├── SortImports.ts # also exports getSortedContent
|
|
280
|
+
│ └── index.ts
|
|
281
|
+
├── eslint/ # deprecated original implementations
|
|
282
|
+
├── eslint.config.ts # dogfooding: ...recommended + disable filename for src
|
|
283
|
+
├── tsconfig.json # ESNext/bundler, no .js extensions
|
|
284
|
+
├── tsup.config.ts # entry src/index.ts, format cjs+esm, dts, splitting:false
|
|
285
|
+
├── package.json # type module, exports ., files [dist]
|
|
286
|
+
└── dist/ # build output (gitignored)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Adding a new rule
|
|
290
|
+
|
|
291
|
+
1. Create `src/rules/MyRule.ts` (`Rule.RuleModule`, `meta.messages`, `fixable` if needed)
|
|
292
|
+
2. Export it from `src/rules/index.ts`
|
|
293
|
+
3. Register in `src/plugin.ts` (`rules: { 'my-rule': myRule }`)
|
|
294
|
+
4. Enable in `src/configs/recommended.ts` (`'ai-rules/my-rule': 'error'`)
|
|
295
|
+
5. Add fixture and test `npx eslint --fix` on `src/__fixtures__/MyRule_test.ts`
|
|
296
|
+
6. `npm run typecheck && npm run build && npx eslint .`
|
|
297
|
+
|
|
298
|
+
### Publishing
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
npm version patch|minor|major
|
|
302
|
+
npm run build
|
|
303
|
+
npm publish --access public
|
|
304
|
+
# prepublishOnly runs build automatically
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Legacy
|
|
308
|
+
|
|
309
|
+
`eslint/` keeps the three original rule files before packaging (deprecated). Source of truth is now `src/rules/`.
|
|
310
|
+
|
|
311
|
+
## License
|
|
312
|
+
|
|
313
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
default: () => index_default,
|
|
34
|
+
filenamePascalCase: () => filenamePascalCase,
|
|
35
|
+
noMultilineImports: () => noMultilineImports,
|
|
36
|
+
plugin: () => plugin,
|
|
37
|
+
recommended: () => recommended,
|
|
38
|
+
sortImports: () => sortImports
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
|
|
42
|
+
// src/configs/recommended.ts
|
|
43
|
+
var import_eslint_plugin_import_x = require("eslint-plugin-import-x");
|
|
44
|
+
var import_config = require("eslint/config");
|
|
45
|
+
var import_eslint_plugin = __toESM(require("@stylistic/eslint-plugin"), 1);
|
|
46
|
+
var import_typescript_eslint = __toESM(require("typescript-eslint"), 1);
|
|
47
|
+
var import_globals = __toESM(require("globals"), 1);
|
|
48
|
+
var import_js = __toESM(require("@eslint/js"), 1);
|
|
49
|
+
|
|
50
|
+
// src/rules/FilenamePascalCase.ts
|
|
51
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
52
|
+
var filenamePascalCase = {
|
|
53
|
+
meta: {
|
|
54
|
+
type: "suggestion",
|
|
55
|
+
docs: { description: "Enforce PascalCase for file names" },
|
|
56
|
+
schema: [],
|
|
57
|
+
messages: {
|
|
58
|
+
invalid: 'File name "{{basename}}" must be in PascalCase. Rename to "{{expected}}".'
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
create(context) {
|
|
62
|
+
const physicalFilename = (
|
|
63
|
+
// eslint 9 flat config
|
|
64
|
+
context.getPhysicalFilename?.() ?? context.physicalFilename ?? context.filename ?? ""
|
|
65
|
+
);
|
|
66
|
+
const cwd = context.getCwd?.() ?? process.cwd();
|
|
67
|
+
const normalizedPhysical = physicalFilename.split(import_node_path.default.sep).join("/");
|
|
68
|
+
const normalizedCwd = cwd.split(import_node_path.default.sep).join("/");
|
|
69
|
+
const relativePath = normalizedPhysical.startsWith(normalizedCwd) ? normalizedPhysical.slice(normalizedCwd.length + 1) : normalizedPhysical;
|
|
70
|
+
if (!relativePath.startsWith("src/") && !relativePath.startsWith("scripts/")) return {};
|
|
71
|
+
const basename = import_node_path.default.basename(relativePath);
|
|
72
|
+
if (basename === "index.ts" || basename === "index.tsx" || basename === "index.js" || basename === "index.jsx") return {};
|
|
73
|
+
if (basename.endsWith(".d.ts")) return {};
|
|
74
|
+
if (basename.endsWith(".css")) return {};
|
|
75
|
+
const ext = import_node_path.default.extname(basename);
|
|
76
|
+
const nameWithoutExt = basename.replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
77
|
+
if (!/^[A-Z][a-zA-Z0-9]*$/.test(nameWithoutExt)) {
|
|
78
|
+
const pascalCase = nameWithoutExt.split(/[-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
79
|
+
const originalExt = basename.slice(nameWithoutExt.length) || ext;
|
|
80
|
+
const expected = `${pascalCase}${originalExt}`;
|
|
81
|
+
context.report({
|
|
82
|
+
loc: { line: 1, column: 0 },
|
|
83
|
+
messageId: "invalid",
|
|
84
|
+
data: { basename, expected }
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/rules/NoMultilineImports.ts
|
|
92
|
+
var noMultilineImports = {
|
|
93
|
+
meta: {
|
|
94
|
+
type: "layout",
|
|
95
|
+
fixable: "code",
|
|
96
|
+
docs: {
|
|
97
|
+
description: "Disallow multiline imports"
|
|
98
|
+
},
|
|
99
|
+
schema: [],
|
|
100
|
+
messages: {
|
|
101
|
+
multilineImport: "Imports must be written on a single line."
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
create(context) {
|
|
105
|
+
const sourceCode = context.sourceCode;
|
|
106
|
+
return {
|
|
107
|
+
ImportDeclaration(node) {
|
|
108
|
+
const text = sourceCode.getText(node);
|
|
109
|
+
if (!text.includes("\n")) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
context.report({
|
|
113
|
+
node,
|
|
114
|
+
messageId: "multilineImport",
|
|
115
|
+
fix(fixer) {
|
|
116
|
+
const firstToken = sourceCode.getFirstToken(node);
|
|
117
|
+
const lastToken = sourceCode.getLastToken(node);
|
|
118
|
+
if (!firstToken || !lastToken) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
let importText = sourceCode.getText(node);
|
|
122
|
+
importText = importText.replace(/\s*\{\s*/g, " { ").replace(/\s*\}\s*/g, " } ").replace(/\s*,\s*/g, ", ").replace(/\s+/g, " ").replace(/ \{ /g, " { ").replace(/ \} /g, " } ").replace(/\s+from\s+/g, " from ").trim().replace(/\{ \s+/g, "{ ").replace(/\s+ \}/g, " }");
|
|
123
|
+
return fixer.replaceText(node, importText);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/rules/SortImports.ts
|
|
132
|
+
var sortImports = {
|
|
133
|
+
meta: {
|
|
134
|
+
type: "layout",
|
|
135
|
+
docs: {
|
|
136
|
+
description: "Sort imports by group and line length descending, collapsing multiline imports"
|
|
137
|
+
},
|
|
138
|
+
fixable: "code",
|
|
139
|
+
schema: [],
|
|
140
|
+
messages: {
|
|
141
|
+
sortRequired: "As importa\xE7\xF5es devem estar ordenadas por grupo e tamanho da linha, ocupando uma \xFAnica linha."
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
create(context) {
|
|
145
|
+
return {
|
|
146
|
+
Program(node) {
|
|
147
|
+
const sourceCode = context.sourceCode;
|
|
148
|
+
const content = sourceCode.text;
|
|
149
|
+
const newContent = getSortedContent(content);
|
|
150
|
+
if (newContent && newContent !== content) {
|
|
151
|
+
context.report({
|
|
152
|
+
node,
|
|
153
|
+
messageId: "sortRequired",
|
|
154
|
+
fix(fixer) {
|
|
155
|
+
return fixer.replaceText(node, newContent);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
function getSortedContent(content) {
|
|
164
|
+
const collapseMultiline = (match) => {
|
|
165
|
+
return match.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").replace(/\s+/g, " ");
|
|
166
|
+
};
|
|
167
|
+
const normalizedContent = content.replace(/import\s+([^'";]+?)\s+from\s+(['"][^'"]+['"])/g, collapseMultiline).replace(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*(?:\s+as\s+\w+)?)\s+from\s+(['"][^'"]+['"])/g, collapseMultiline);
|
|
168
|
+
const lines = normalizedContent.split("\n");
|
|
169
|
+
const directiveLines = [];
|
|
170
|
+
const reactFirstLine = [];
|
|
171
|
+
const externalLines = [];
|
|
172
|
+
const internalLines = [];
|
|
173
|
+
const reExportLines = [];
|
|
174
|
+
const nonImportLines = [];
|
|
175
|
+
let inImportBlock = false;
|
|
176
|
+
let canAcceptDirectives = true;
|
|
177
|
+
for (let i = 0; i < lines.length; i++) {
|
|
178
|
+
const trimmed = lines[i].trim();
|
|
179
|
+
if (/^(function|const|let|var|class|interface|enum)\b/.test(trimmed) || /^(type|export)\b/.test(trimmed) && !/ from ['"]/.test(trimmed) && !/^export\s*\{[^}]*\}\s*from/.test(trimmed) && !/^export\s*\*/.test(trimmed) || trimmed.startsWith("}")) {
|
|
180
|
+
canAcceptDirectives = false;
|
|
181
|
+
}
|
|
182
|
+
if (inImportBlock && trimmed === "") continue;
|
|
183
|
+
if (canAcceptDirectives && /^['"]use (client|server|strict)['"];?$/.test(trimmed)) {
|
|
184
|
+
directiveLines.push(lines[i]);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const isReExport = /^export\s+(type\s+)?\{[^}]*\}\s+from\s+['"]/.test(trimmed) || /^export\s+\*(\s+as\s+\w+)?\s+from\s+['"]/.test(trimmed);
|
|
188
|
+
if (isReExport) {
|
|
189
|
+
const m = lines[i].match(/from\s+['"]([^'"]+)['"]/);
|
|
190
|
+
if (m) reExportLines.push({ line: lines[i], from: m[1] });
|
|
191
|
+
inImportBlock = true;
|
|
192
|
+
canAcceptDirectives = false;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const isImport = /^import\s/.test(trimmed) || /^import\{/.test(trimmed);
|
|
196
|
+
if (isImport) {
|
|
197
|
+
inImportBlock = true;
|
|
198
|
+
canAcceptDirectives = false;
|
|
199
|
+
const fromMatch = lines[i].match(/from\s+['"]([^'"]+)['"]/);
|
|
200
|
+
const seMatch = lines[i].match(/^import\s+['"]([^'"]+)['"]/);
|
|
201
|
+
const from = fromMatch ? fromMatch[1] : seMatch ? seMatch[1] : null;
|
|
202
|
+
if (!from) {
|
|
203
|
+
nonImportLines.push(lines[i]);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const isTypeOnly = /^import\s+type\b/.test(trimmed);
|
|
207
|
+
const isInternal = from.startsWith(".") || from.startsWith("@/");
|
|
208
|
+
const isReactEntry = !isTypeOnly && (from === "react" || from.startsWith("react/"));
|
|
209
|
+
if (isReactEntry) {
|
|
210
|
+
reactFirstLine.push(lines[i]);
|
|
211
|
+
} else if (isInternal) {
|
|
212
|
+
internalLines.push({ line: lines[i], from });
|
|
213
|
+
} else {
|
|
214
|
+
externalLines.push({ line: lines[i], from });
|
|
215
|
+
}
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
inImportBlock = false;
|
|
219
|
+
nonImportLines.push(lines[i]);
|
|
220
|
+
}
|
|
221
|
+
if (reactFirstLine.length === 0 && externalLines.length === 0 && internalLines.length === 0 && reExportLines.length === 0) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
const byLengthDesc = (a, b) => b.line.length !== a.line.length ? b.line.length - a.line.length : a.line.localeCompare(b.line);
|
|
225
|
+
externalLines.sort(byLengthDesc);
|
|
226
|
+
internalLines.sort(byLengthDesc);
|
|
227
|
+
reExportLines.sort(byLengthDesc);
|
|
228
|
+
const blocks = [];
|
|
229
|
+
if (directiveLines.length > 0) blocks.push(directiveLines.join("\n"));
|
|
230
|
+
const externalBlock = [...reactFirstLine, ...externalLines.map((i) => i.line)];
|
|
231
|
+
if (externalBlock.length > 0) {
|
|
232
|
+
if (blocks.length > 0) blocks.push("");
|
|
233
|
+
blocks.push(externalBlock.join("\n"));
|
|
234
|
+
}
|
|
235
|
+
if (internalLines.length > 0) {
|
|
236
|
+
if (blocks.length > 0) blocks.push("");
|
|
237
|
+
blocks.push(internalLines.map((i) => i.line).join("\n"));
|
|
238
|
+
}
|
|
239
|
+
if (reExportLines.length > 0) {
|
|
240
|
+
if (blocks.length > 0) blocks.push("");
|
|
241
|
+
blocks.push(reExportLines.map((i) => i.line).join("\n"));
|
|
242
|
+
}
|
|
243
|
+
const rest = nonImportLines.join("\n").replace(/^\n+/, "");
|
|
244
|
+
let newContent;
|
|
245
|
+
if (blocks.length > 0 && rest.length > 0) {
|
|
246
|
+
newContent = blocks.join("\n") + "\n\n\n" + rest;
|
|
247
|
+
} else if (blocks.length > 0) {
|
|
248
|
+
newContent = blocks.join("\n") + "\n";
|
|
249
|
+
} else {
|
|
250
|
+
newContent = rest;
|
|
251
|
+
}
|
|
252
|
+
return newContent;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/plugin.ts
|
|
256
|
+
var plugin = {
|
|
257
|
+
meta: {
|
|
258
|
+
name: "eslint-plugin-ai-rules",
|
|
259
|
+
version: "0.1.0"
|
|
260
|
+
},
|
|
261
|
+
rules: {
|
|
262
|
+
"filename-pascal-case": filenamePascalCase,
|
|
263
|
+
"no-multiline-imports": noMultilineImports,
|
|
264
|
+
"sort-imports": sortImports
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// src/configs/recommended.ts
|
|
269
|
+
var recommended = (0, import_config.defineConfig)([
|
|
270
|
+
(0, import_config.globalIgnores)(["dist", "src/services/generated", "scripts/types"]),
|
|
271
|
+
{
|
|
272
|
+
files: ["**/*.{ts,tsx}"],
|
|
273
|
+
extends: [import_js.default.configs.recommended, import_typescript_eslint.default.configs.recommended],
|
|
274
|
+
languageOptions: {
|
|
275
|
+
globals: import_globals.default.browser
|
|
276
|
+
},
|
|
277
|
+
plugins: {
|
|
278
|
+
"@stylistic": import_eslint_plugin.default,
|
|
279
|
+
"import-x": import_eslint_plugin_import_x.importX,
|
|
280
|
+
"ai-rules": plugin
|
|
281
|
+
},
|
|
282
|
+
settings: {
|
|
283
|
+
"import-x/resolver-next": [
|
|
284
|
+
(0, import_eslint_plugin_import_x.createNodeResolver)({
|
|
285
|
+
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"]
|
|
286
|
+
})
|
|
287
|
+
]
|
|
288
|
+
},
|
|
289
|
+
rules: {
|
|
290
|
+
"ai-rules/sort-imports": "error",
|
|
291
|
+
"ai-rules/no-multiline-imports": "error",
|
|
292
|
+
"ai-rules/filename-pascal-case": "error",
|
|
293
|
+
"max-len": "off",
|
|
294
|
+
"import-x/no-duplicates": "error",
|
|
295
|
+
"import-x/no-default-export": "off",
|
|
296
|
+
"@stylistic/semi": ["error", "never"],
|
|
297
|
+
"@typescript-eslint/consistent-type-imports": [
|
|
298
|
+
"error",
|
|
299
|
+
{ prefer: "type-imports" }
|
|
300
|
+
],
|
|
301
|
+
"@typescript-eslint/no-unused-vars": [
|
|
302
|
+
"error",
|
|
303
|
+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" }
|
|
304
|
+
],
|
|
305
|
+
"@typescript-eslint/naming-convention": [
|
|
306
|
+
"error",
|
|
307
|
+
{ selector: "interface", format: ["PascalCase"], prefix: ["I"] },
|
|
308
|
+
{ selector: "typeAlias", format: ["PascalCase"], prefix: ["T"] }
|
|
309
|
+
]
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
files: ["**/*.d.ts", "scripts/**/*"],
|
|
314
|
+
rules: {
|
|
315
|
+
"@typescript-eslint/naming-convention": "off"
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
]);
|
|
319
|
+
|
|
320
|
+
// src/index.ts
|
|
321
|
+
var aiGuardPlugin = {
|
|
322
|
+
...plugin,
|
|
323
|
+
configs: {
|
|
324
|
+
recommended
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
var index_default = aiGuardPlugin;
|
|
328
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
329
|
+
0 && (module.exports = {
|
|
330
|
+
filenamePascalCase,
|
|
331
|
+
noMultilineImports,
|
|
332
|
+
plugin,
|
|
333
|
+
recommended,
|
|
334
|
+
sortImports
|
|
335
|
+
});
|
|
336
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/configs/recommended.ts","../src/rules/FilenamePascalCase.ts","../src/rules/NoMultilineImports.ts","../src/rules/SortImports.ts","../src/plugin.ts"],"sourcesContent":["import { recommended } from './configs/recommended'\nimport { plugin } from './plugin'\n\nexport * from './rules/index'\n\n\nconst aiGuardPlugin = {\n ...plugin,\n configs: {\n recommended,\n },\n}\n\nexport default aiGuardPlugin\nexport { plugin }\nexport { recommended }","import { importX, createNodeResolver } from 'eslint-plugin-import-x'\nimport { defineConfig, globalIgnores } from 'eslint/config'\nimport stylistic from '@stylistic/eslint-plugin'\nimport tseslint from 'typescript-eslint'\nimport globals from 'globals'\nimport js from '@eslint/js'\n\nimport { plugin } from '../plugin'\n\n\nexport const recommended = defineConfig([\n globalIgnores(['dist', 'src/services/generated', 'scripts/types']),\n {\n files: ['**/*.{ts,tsx}'],\n extends: [js.configs.recommended, tseslint.configs.recommended],\n languageOptions: {\n globals: globals.browser,\n },\n plugins: {\n '@stylistic': stylistic,\n 'import-x': importX,\n 'ai-rules': plugin,\n },\n settings: {\n 'import-x/resolver-next': [\n createNodeResolver({\n extensions: ['.ts', '.tsx', '.d.ts', '.js', '.jsx'],\n }),\n ],\n },\n rules: {\n 'ai-rules/sort-imports': 'error',\n 'ai-rules/no-multiline-imports': 'error',\n 'ai-rules/filename-pascal-case': 'error',\n 'max-len': 'off',\n 'import-x/no-duplicates': 'error',\n 'import-x/no-default-export': 'off',\n '@stylistic/semi': ['error', 'never'],\n '@typescript-eslint/consistent-type-imports': [\n 'error',\n { prefer: 'type-imports' },\n ],\n '@typescript-eslint/no-unused-vars': [\n 'error',\n { argsIgnorePattern: '^_', varsIgnorePattern: '^_' },\n ],\n '@typescript-eslint/naming-convention': [\n 'error',\n { selector: 'interface', format: ['PascalCase'], prefix: ['I'] },\n { selector: 'typeAlias', format: ['PascalCase'], prefix: ['T'] },\n ],\n },\n },\n {\n files: ['**/*.d.ts', 'scripts/**/*'],\n rules: {\n '@typescript-eslint/naming-convention': 'off',\n },\n },\n])\n\nexport default recommended\n","import type { Rule } from 'eslint'\nimport path from 'node:path'\n\n\nexport const filenamePascalCase: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: { description: 'Enforce PascalCase for file names' },\n schema: [],\n messages: {\n invalid: 'File name \"{{basename}}\" must be in PascalCase. Rename to \"{{expected}}\".',\n },\n },\n create(context) {\n const physicalFilename =\n // eslint 9 flat config\n (context as unknown as { getPhysicalFilename?: () => string }).getPhysicalFilename?.() ??\n (context as unknown as { physicalFilename?: string }).physicalFilename ??\n context.filename ??\n ''\n\n const cwd =\n (context as unknown as { getCwd?: () => string }).getCwd?.() ?? process.cwd()\n\n // Normaliza para posix para comparar com src/ e scripts/\n const normalizedPhysical = physicalFilename.split(path.sep).join('/')\n const normalizedCwd = cwd.split(path.sep).join('/')\n\n const relativePath = normalizedPhysical.startsWith(normalizedCwd)\n ? normalizedPhysical.slice(normalizedCwd.length + 1)\n : normalizedPhysical\n\n if (!relativePath.startsWith('src/') && !relativePath.startsWith('scripts/')) return {}\n\n const basename = path.basename(relativePath)\n\n if (basename === 'index.ts' || basename === 'index.tsx' || basename === 'index.js' || basename === 'index.jsx') return {}\n if (basename.endsWith('.d.ts')) return {}\n if (basename.endsWith('.css')) return {}\n\n const ext = path.extname(basename) // .ts\n // Para casos como Component.spec.ts -> ext .ts, nameWithoutExt Component.spec - tratamos mantendo só base antes do primeiro ponto?\n // Mantemos compat com original: remove apenas última extensão .ts/.tsx/.js/.jsx\n const nameWithoutExt = basename.replace(/\\.(ts|tsx|js|jsx)$/, '')\n\n if (!/^[A-Z][a-zA-Z0-9]*$/.test(nameWithoutExt)) {\n const pascalCase = nameWithoutExt\n .split(/[-_]/)\n .map(part => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')\n\n // Preserva extensão original (ex: .tsx)\n const originalExt = basename.slice(nameWithoutExt.length) || ext\n const expected = `${pascalCase}${originalExt}`\n\n context.report({\n loc: { line: 1, column: 0 },\n messageId: 'invalid',\n data: { basename, expected },\n })\n }\n\n return {}\n },\n}\n","import type { Rule } from 'eslint'\n\n\nexport const noMultilineImports: Rule.RuleModule = {\n meta: {\n type: 'layout',\n fixable: 'code',\n docs: {\n description: 'Disallow multiline imports',\n },\n schema: [],\n messages: {\n multilineImport: 'Imports must be written on a single line.',\n },\n },\n\n create(context) {\n const sourceCode = context.sourceCode\n\n return {\n ImportDeclaration(node) {\n const text = sourceCode.getText(node)\n\n if (!text.includes('\\n')) {\n return\n }\n\n context.report({\n node,\n messageId: 'multilineImport',\n\n fix(fixer) {\n const firstToken = sourceCode.getFirstToken(node)\n const lastToken = sourceCode.getLastToken(node)\n\n if (!firstToken || !lastToken) {\n return null\n }\n\n let importText = sourceCode.getText(node)\n\n importText = importText\n .replace(/\\s*\\{\\s*/g, ' { ')\n .replace(/\\s*\\}\\s*/g, ' } ')\n .replace(/\\s*,\\s*/g, ', ')\n .replace(/\\s+/g, ' ')\n .replace(/ \\{ /g, ' { ')\n .replace(/ \\} /g, ' } ')\n .replace(/\\s+from\\s+/g, ' from ')\n .trim()\n // Corrige espaços colapsados em torno de { e }\n .replace(/\\{ \\s+/g, '{ ')\n .replace(/\\s+ \\}/g, ' }')\n\n return fixer.replaceText(node, importText)\n },\n })\n },\n }\n },\n}\n","import type { Rule } from 'eslint'\n\n\nexport const sortImports: Rule.RuleModule = {\n meta: {\n type: 'layout',\n docs: {\n description: 'Sort imports by group and line length descending, collapsing multiline imports',\n },\n fixable: 'code',\n schema: [],\n messages: {\n sortRequired: 'As importações devem estar ordenadas por grupo e tamanho da linha, ocupando uma única linha.',\n },\n },\n create(context) {\n return {\n Program(node) {\n const sourceCode = context.sourceCode\n const content = sourceCode.text\n\n const newContent = getSortedContent(content)\n\n if (newContent && newContent !== content) {\n context.report({\n node,\n messageId: 'sortRequired',\n fix(fixer) {\n return fixer.replaceText(node, newContent)\n },\n })\n }\n },\n }\n },\n}\n\n// ---------------------------------------------------------------------------\n// Tipos auxiliares\n// ---------------------------------------------------------------------------\ntype TImportItem = {\n line: string\n from: string\n}\n\n// ---------------------------------------------------------------------------\n// Lógica Core - exportada para teste e reutilização\n// ---------------------------------------------------------------------------\nexport function getSortedContent(content: string): string | null {\n const collapseMultiline = (match: string) => {\n return match\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n .replace(/\\/\\/.*$/gm, '')\n .replace(/\\s+/g, ' ')\n }\n\n const normalizedContent = content\n .replace(/import\\s+([^'\";]+?)\\s+from\\s+(['\"][^'\"]+['\"])/g, collapseMultiline)\n // Apenas re-exports válidos: export { ... } from / export * from / export * as X from / export type { ... } from\n .replace(/export\\s+(?:type\\s+)?(?:\\{[^}]*\\}|\\*(?:\\s+as\\s+\\w+)?)\\s+from\\s+(['\"][^'\"]+['\"])/g, collapseMultiline)\n\n const lines: string[] = normalizedContent.split('\\n')\n\n const directiveLines: string[] = []\n const reactFirstLine: string[] = []\n const externalLines: TImportItem[] = []\n const internalLines: TImportItem[] = []\n const reExportLines: TImportItem[] = []\n const nonImportLines: string[] = []\n\n let inImportBlock = false\n let canAcceptDirectives = true\n\n for (let i = 0; i < lines.length; i++) {\n const trimmed = lines[i].trim()\n\n if (\n /^(function|const|let|var|class|interface|enum)\\b/.test(trimmed) ||\n (/^(type|export)\\b/.test(trimmed) && !/ from ['\"]/.test(trimmed) && !/^export\\s*\\{[^}]*\\}\\s*from/.test(trimmed) && !/^export\\s*\\*/.test(trimmed)) ||\n trimmed.startsWith('}')\n ) {\n canAcceptDirectives = false\n }\n\n if (inImportBlock && trimmed === '') continue\n\n if (canAcceptDirectives && /^['\"]use (client|server|strict)['\"];?$/.test(trimmed)) {\n directiveLines.push(lines[i])\n continue\n }\n\n const isReExport =\n /^export\\s+(type\\s+)?\\{[^}]*\\}\\s+from\\s+['\"]/.test(trimmed) ||\n /^export\\s+\\*(\\s+as\\s+\\w+)?\\s+from\\s+['\"]/.test(trimmed)\n\n if (isReExport) {\n const m = lines[i].match(/from\\s+['\"]([^'\"]+)['\"]/)\n if (m) reExportLines.push({ line: lines[i], from: m[1] })\n inImportBlock = true\n canAcceptDirectives = false\n continue\n }\n\n const isImport = /^import\\s/.test(trimmed) || /^import\\{/.test(trimmed)\n\n if (isImport) {\n inImportBlock = true\n canAcceptDirectives = false\n\n const fromMatch = lines[i].match(/from\\s+['\"]([^'\"]+)['\"]/)\n const seMatch = lines[i].match(/^import\\s+['\"]([^'\"]+)['\"]/)\n const from = fromMatch ? fromMatch[1] : seMatch ? seMatch[1] : null\n\n if (!from) {\n nonImportLines.push(lines[i])\n continue\n }\n\n const isTypeOnly = /^import\\s+type\\b/.test(trimmed)\n const isInternal = from.startsWith('.') || from.startsWith('@/')\n const isReactEntry = !isTypeOnly && (from === 'react' || from.startsWith('react/'))\n\n if (isReactEntry) {\n reactFirstLine.push(lines[i])\n } else if (isInternal) {\n internalLines.push({ line: lines[i], from })\n } else {\n externalLines.push({ line: lines[i], from })\n }\n continue\n }\n\n inImportBlock = false\n nonImportLines.push(lines[i])\n }\n\n if (reactFirstLine.length === 0 && externalLines.length === 0 && internalLines.length === 0 && reExportLines.length === 0) {\n return null\n }\n\n const byLengthDesc = (a: TImportItem, b: TImportItem) =>\n b.line.length !== a.line.length ? b.line.length - a.line.length : a.line.localeCompare(b.line)\n\n externalLines.sort(byLengthDesc)\n internalLines.sort(byLengthDesc)\n reExportLines.sort(byLengthDesc)\n\n const blocks: string[] = []\n\n if (directiveLines.length > 0) blocks.push(directiveLines.join('\\n'))\n\n const externalBlock = [...reactFirstLine, ...externalLines.map(i => i.line)]\n if (externalBlock.length > 0) {\n if (blocks.length > 0) blocks.push('')\n blocks.push(externalBlock.join('\\n'))\n }\n\n if (internalLines.length > 0) {\n if (blocks.length > 0) blocks.push('')\n blocks.push(internalLines.map(i => i.line).join('\\n'))\n }\n\n if (reExportLines.length > 0) {\n if (blocks.length > 0) blocks.push('')\n blocks.push(reExportLines.map(i => i.line).join('\\n'))\n }\n\n const rest = nonImportLines.join('\\n').replace(/^\\n+/, '')\n\n let newContent: string\n if (blocks.length > 0 && rest.length > 0) {\n newContent = blocks.join('\\n') + '\\n\\n\\n' + rest\n } else if (blocks.length > 0) {\n newContent = blocks.join('\\n') + '\\n'\n } else {\n newContent = rest\n }\n\n return newContent\n}\n","import { filenamePascalCase } from './rules/FilenamePascalCase'\nimport { noMultilineImports } from './rules/NoMultilineImports'\nimport { sortImports } from './rules/SortImports'\n\n\nexport const plugin = {\n meta: {\n name: 'eslint-plugin-ai-rules',\n version: '0.1.0',\n },\n rules: {\n 'filename-pascal-case': filenamePascalCase,\n 'no-multiline-imports': noMultilineImports,\n 'sort-imports': sortImports,\n },\n} as const\n"],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,QACA,EAAE,QAAQ,eAAe;AAAA,MAC3B;AAAA,MACA,qCAAqC;AAAA,QACnC;AAAA,QACA,EAAE,mBAAmB,MAAM,mBAAmB,KAAK;AAAA,MACrD;AAAA,MACA,wCAAwC;AAAA,QACtC;AAAA,QACA,EAAE,UAAU,aAAa,QAAQ,CAAC,YAAY,GAAG,QAAQ,CAAC,GAAG,EAAE;AAAA,QAC/D,EAAE,UAAU,aAAa,QAAQ,CAAC,YAAY,GAAG,QAAQ,CAAC,GAAG,EAAE;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AAAA,EACA;AAAA,IACE,OAAO,CAAC,aAAa,cAAc;AAAA,IACnC,OAAO;AAAA,MACL,wCAAwC;AAAA,IAC1C;AAAA,EACF;AACF,CAAC;;;ADrDD,IAAM,gBAAgB;AAAA,EACpB,GAAG;AAAA,EACH,SAAS;AAAA,IACP;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["path","js","tseslint","globals","stylistic"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as eslint from 'eslint';
|
|
2
|
+
import { Rule } from 'eslint';
|
|
3
|
+
import * as eslint_config from 'eslint/config';
|
|
4
|
+
|
|
5
|
+
declare const recommended: eslint_config.Config[];
|
|
6
|
+
|
|
7
|
+
declare const plugin: {
|
|
8
|
+
readonly meta: {
|
|
9
|
+
readonly name: "eslint-plugin-ai-rules";
|
|
10
|
+
readonly version: "0.1.0";
|
|
11
|
+
};
|
|
12
|
+
readonly rules: {
|
|
13
|
+
readonly 'filename-pascal-case': eslint.Rule.RuleModule;
|
|
14
|
+
readonly 'no-multiline-imports': eslint.Rule.RuleModule;
|
|
15
|
+
readonly 'sort-imports': eslint.Rule.RuleModule;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
declare const filenamePascalCase: Rule.RuleModule;
|
|
20
|
+
|
|
21
|
+
declare const noMultilineImports: Rule.RuleModule;
|
|
22
|
+
|
|
23
|
+
declare const sortImports: Rule.RuleModule;
|
|
24
|
+
|
|
25
|
+
declare const aiGuardPlugin: {
|
|
26
|
+
configs: {
|
|
27
|
+
recommended: eslint_config.Config[];
|
|
28
|
+
};
|
|
29
|
+
meta: {
|
|
30
|
+
readonly name: "eslint-plugin-ai-rules";
|
|
31
|
+
readonly version: "0.1.0";
|
|
32
|
+
};
|
|
33
|
+
rules: {
|
|
34
|
+
readonly 'filename-pascal-case': eslint.Rule.RuleModule;
|
|
35
|
+
readonly 'no-multiline-imports': eslint.Rule.RuleModule;
|
|
36
|
+
readonly 'sort-imports': eslint.Rule.RuleModule;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { aiGuardPlugin as default, filenamePascalCase, noMultilineImports, plugin, recommended, sortImports };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as eslint from 'eslint';
|
|
2
|
+
import { Rule } from 'eslint';
|
|
3
|
+
import * as eslint_config from 'eslint/config';
|
|
4
|
+
|
|
5
|
+
declare const recommended: eslint_config.Config[];
|
|
6
|
+
|
|
7
|
+
declare const plugin: {
|
|
8
|
+
readonly meta: {
|
|
9
|
+
readonly name: "eslint-plugin-ai-rules";
|
|
10
|
+
readonly version: "0.1.0";
|
|
11
|
+
};
|
|
12
|
+
readonly rules: {
|
|
13
|
+
readonly 'filename-pascal-case': eslint.Rule.RuleModule;
|
|
14
|
+
readonly 'no-multiline-imports': eslint.Rule.RuleModule;
|
|
15
|
+
readonly 'sort-imports': eslint.Rule.RuleModule;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
declare const filenamePascalCase: Rule.RuleModule;
|
|
20
|
+
|
|
21
|
+
declare const noMultilineImports: Rule.RuleModule;
|
|
22
|
+
|
|
23
|
+
declare const sortImports: Rule.RuleModule;
|
|
24
|
+
|
|
25
|
+
declare const aiGuardPlugin: {
|
|
26
|
+
configs: {
|
|
27
|
+
recommended: eslint_config.Config[];
|
|
28
|
+
};
|
|
29
|
+
meta: {
|
|
30
|
+
readonly name: "eslint-plugin-ai-rules";
|
|
31
|
+
readonly version: "0.1.0";
|
|
32
|
+
};
|
|
33
|
+
rules: {
|
|
34
|
+
readonly 'filename-pascal-case': eslint.Rule.RuleModule;
|
|
35
|
+
readonly 'no-multiline-imports': eslint.Rule.RuleModule;
|
|
36
|
+
readonly 'sort-imports': eslint.Rule.RuleModule;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { aiGuardPlugin as default, filenamePascalCase, noMultilineImports, plugin, recommended, sortImports };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// src/configs/recommended.ts
|
|
2
|
+
import { importX, createNodeResolver } from "eslint-plugin-import-x";
|
|
3
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
4
|
+
import stylistic from "@stylistic/eslint-plugin";
|
|
5
|
+
import tseslint from "typescript-eslint";
|
|
6
|
+
import globals from "globals";
|
|
7
|
+
import js from "@eslint/js";
|
|
8
|
+
|
|
9
|
+
// src/rules/FilenamePascalCase.ts
|
|
10
|
+
import path from "path";
|
|
11
|
+
var filenamePascalCase = {
|
|
12
|
+
meta: {
|
|
13
|
+
type: "suggestion",
|
|
14
|
+
docs: { description: "Enforce PascalCase for file names" },
|
|
15
|
+
schema: [],
|
|
16
|
+
messages: {
|
|
17
|
+
invalid: 'File name "{{basename}}" must be in PascalCase. Rename to "{{expected}}".'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
create(context) {
|
|
21
|
+
const physicalFilename = (
|
|
22
|
+
// eslint 9 flat config
|
|
23
|
+
context.getPhysicalFilename?.() ?? context.physicalFilename ?? context.filename ?? ""
|
|
24
|
+
);
|
|
25
|
+
const cwd = context.getCwd?.() ?? process.cwd();
|
|
26
|
+
const normalizedPhysical = physicalFilename.split(path.sep).join("/");
|
|
27
|
+
const normalizedCwd = cwd.split(path.sep).join("/");
|
|
28
|
+
const relativePath = normalizedPhysical.startsWith(normalizedCwd) ? normalizedPhysical.slice(normalizedCwd.length + 1) : normalizedPhysical;
|
|
29
|
+
if (!relativePath.startsWith("src/") && !relativePath.startsWith("scripts/")) return {};
|
|
30
|
+
const basename = path.basename(relativePath);
|
|
31
|
+
if (basename === "index.ts" || basename === "index.tsx" || basename === "index.js" || basename === "index.jsx") return {};
|
|
32
|
+
if (basename.endsWith(".d.ts")) return {};
|
|
33
|
+
if (basename.endsWith(".css")) return {};
|
|
34
|
+
const ext = path.extname(basename);
|
|
35
|
+
const nameWithoutExt = basename.replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
36
|
+
if (!/^[A-Z][a-zA-Z0-9]*$/.test(nameWithoutExt)) {
|
|
37
|
+
const pascalCase = nameWithoutExt.split(/[-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
38
|
+
const originalExt = basename.slice(nameWithoutExt.length) || ext;
|
|
39
|
+
const expected = `${pascalCase}${originalExt}`;
|
|
40
|
+
context.report({
|
|
41
|
+
loc: { line: 1, column: 0 },
|
|
42
|
+
messageId: "invalid",
|
|
43
|
+
data: { basename, expected }
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/rules/NoMultilineImports.ts
|
|
51
|
+
var noMultilineImports = {
|
|
52
|
+
meta: {
|
|
53
|
+
type: "layout",
|
|
54
|
+
fixable: "code",
|
|
55
|
+
docs: {
|
|
56
|
+
description: "Disallow multiline imports"
|
|
57
|
+
},
|
|
58
|
+
schema: [],
|
|
59
|
+
messages: {
|
|
60
|
+
multilineImport: "Imports must be written on a single line."
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
create(context) {
|
|
64
|
+
const sourceCode = context.sourceCode;
|
|
65
|
+
return {
|
|
66
|
+
ImportDeclaration(node) {
|
|
67
|
+
const text = sourceCode.getText(node);
|
|
68
|
+
if (!text.includes("\n")) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
context.report({
|
|
72
|
+
node,
|
|
73
|
+
messageId: "multilineImport",
|
|
74
|
+
fix(fixer) {
|
|
75
|
+
const firstToken = sourceCode.getFirstToken(node);
|
|
76
|
+
const lastToken = sourceCode.getLastToken(node);
|
|
77
|
+
if (!firstToken || !lastToken) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
let importText = sourceCode.getText(node);
|
|
81
|
+
importText = importText.replace(/\s*\{\s*/g, " { ").replace(/\s*\}\s*/g, " } ").replace(/\s*,\s*/g, ", ").replace(/\s+/g, " ").replace(/ \{ /g, " { ").replace(/ \} /g, " } ").replace(/\s+from\s+/g, " from ").trim().replace(/\{ \s+/g, "{ ").replace(/\s+ \}/g, " }");
|
|
82
|
+
return fixer.replaceText(node, importText);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/rules/SortImports.ts
|
|
91
|
+
var sortImports = {
|
|
92
|
+
meta: {
|
|
93
|
+
type: "layout",
|
|
94
|
+
docs: {
|
|
95
|
+
description: "Sort imports by group and line length descending, collapsing multiline imports"
|
|
96
|
+
},
|
|
97
|
+
fixable: "code",
|
|
98
|
+
schema: [],
|
|
99
|
+
messages: {
|
|
100
|
+
sortRequired: "As importa\xE7\xF5es devem estar ordenadas por grupo e tamanho da linha, ocupando uma \xFAnica linha."
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
create(context) {
|
|
104
|
+
return {
|
|
105
|
+
Program(node) {
|
|
106
|
+
const sourceCode = context.sourceCode;
|
|
107
|
+
const content = sourceCode.text;
|
|
108
|
+
const newContent = getSortedContent(content);
|
|
109
|
+
if (newContent && newContent !== content) {
|
|
110
|
+
context.report({
|
|
111
|
+
node,
|
|
112
|
+
messageId: "sortRequired",
|
|
113
|
+
fix(fixer) {
|
|
114
|
+
return fixer.replaceText(node, newContent);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
function getSortedContent(content) {
|
|
123
|
+
const collapseMultiline = (match) => {
|
|
124
|
+
return match.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").replace(/\s+/g, " ");
|
|
125
|
+
};
|
|
126
|
+
const normalizedContent = content.replace(/import\s+([^'";]+?)\s+from\s+(['"][^'"]+['"])/g, collapseMultiline).replace(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*(?:\s+as\s+\w+)?)\s+from\s+(['"][^'"]+['"])/g, collapseMultiline);
|
|
127
|
+
const lines = normalizedContent.split("\n");
|
|
128
|
+
const directiveLines = [];
|
|
129
|
+
const reactFirstLine = [];
|
|
130
|
+
const externalLines = [];
|
|
131
|
+
const internalLines = [];
|
|
132
|
+
const reExportLines = [];
|
|
133
|
+
const nonImportLines = [];
|
|
134
|
+
let inImportBlock = false;
|
|
135
|
+
let canAcceptDirectives = true;
|
|
136
|
+
for (let i = 0; i < lines.length; i++) {
|
|
137
|
+
const trimmed = lines[i].trim();
|
|
138
|
+
if (/^(function|const|let|var|class|interface|enum)\b/.test(trimmed) || /^(type|export)\b/.test(trimmed) && !/ from ['"]/.test(trimmed) && !/^export\s*\{[^}]*\}\s*from/.test(trimmed) && !/^export\s*\*/.test(trimmed) || trimmed.startsWith("}")) {
|
|
139
|
+
canAcceptDirectives = false;
|
|
140
|
+
}
|
|
141
|
+
if (inImportBlock && trimmed === "") continue;
|
|
142
|
+
if (canAcceptDirectives && /^['"]use (client|server|strict)['"];?$/.test(trimmed)) {
|
|
143
|
+
directiveLines.push(lines[i]);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const isReExport = /^export\s+(type\s+)?\{[^}]*\}\s+from\s+['"]/.test(trimmed) || /^export\s+\*(\s+as\s+\w+)?\s+from\s+['"]/.test(trimmed);
|
|
147
|
+
if (isReExport) {
|
|
148
|
+
const m = lines[i].match(/from\s+['"]([^'"]+)['"]/);
|
|
149
|
+
if (m) reExportLines.push({ line: lines[i], from: m[1] });
|
|
150
|
+
inImportBlock = true;
|
|
151
|
+
canAcceptDirectives = false;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const isImport = /^import\s/.test(trimmed) || /^import\{/.test(trimmed);
|
|
155
|
+
if (isImport) {
|
|
156
|
+
inImportBlock = true;
|
|
157
|
+
canAcceptDirectives = false;
|
|
158
|
+
const fromMatch = lines[i].match(/from\s+['"]([^'"]+)['"]/);
|
|
159
|
+
const seMatch = lines[i].match(/^import\s+['"]([^'"]+)['"]/);
|
|
160
|
+
const from = fromMatch ? fromMatch[1] : seMatch ? seMatch[1] : null;
|
|
161
|
+
if (!from) {
|
|
162
|
+
nonImportLines.push(lines[i]);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const isTypeOnly = /^import\s+type\b/.test(trimmed);
|
|
166
|
+
const isInternal = from.startsWith(".") || from.startsWith("@/");
|
|
167
|
+
const isReactEntry = !isTypeOnly && (from === "react" || from.startsWith("react/"));
|
|
168
|
+
if (isReactEntry) {
|
|
169
|
+
reactFirstLine.push(lines[i]);
|
|
170
|
+
} else if (isInternal) {
|
|
171
|
+
internalLines.push({ line: lines[i], from });
|
|
172
|
+
} else {
|
|
173
|
+
externalLines.push({ line: lines[i], from });
|
|
174
|
+
}
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
inImportBlock = false;
|
|
178
|
+
nonImportLines.push(lines[i]);
|
|
179
|
+
}
|
|
180
|
+
if (reactFirstLine.length === 0 && externalLines.length === 0 && internalLines.length === 0 && reExportLines.length === 0) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
const byLengthDesc = (a, b) => b.line.length !== a.line.length ? b.line.length - a.line.length : a.line.localeCompare(b.line);
|
|
184
|
+
externalLines.sort(byLengthDesc);
|
|
185
|
+
internalLines.sort(byLengthDesc);
|
|
186
|
+
reExportLines.sort(byLengthDesc);
|
|
187
|
+
const blocks = [];
|
|
188
|
+
if (directiveLines.length > 0) blocks.push(directiveLines.join("\n"));
|
|
189
|
+
const externalBlock = [...reactFirstLine, ...externalLines.map((i) => i.line)];
|
|
190
|
+
if (externalBlock.length > 0) {
|
|
191
|
+
if (blocks.length > 0) blocks.push("");
|
|
192
|
+
blocks.push(externalBlock.join("\n"));
|
|
193
|
+
}
|
|
194
|
+
if (internalLines.length > 0) {
|
|
195
|
+
if (blocks.length > 0) blocks.push("");
|
|
196
|
+
blocks.push(internalLines.map((i) => i.line).join("\n"));
|
|
197
|
+
}
|
|
198
|
+
if (reExportLines.length > 0) {
|
|
199
|
+
if (blocks.length > 0) blocks.push("");
|
|
200
|
+
blocks.push(reExportLines.map((i) => i.line).join("\n"));
|
|
201
|
+
}
|
|
202
|
+
const rest = nonImportLines.join("\n").replace(/^\n+/, "");
|
|
203
|
+
let newContent;
|
|
204
|
+
if (blocks.length > 0 && rest.length > 0) {
|
|
205
|
+
newContent = blocks.join("\n") + "\n\n\n" + rest;
|
|
206
|
+
} else if (blocks.length > 0) {
|
|
207
|
+
newContent = blocks.join("\n") + "\n";
|
|
208
|
+
} else {
|
|
209
|
+
newContent = rest;
|
|
210
|
+
}
|
|
211
|
+
return newContent;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/plugin.ts
|
|
215
|
+
var plugin = {
|
|
216
|
+
meta: {
|
|
217
|
+
name: "eslint-plugin-ai-rules",
|
|
218
|
+
version: "0.1.0"
|
|
219
|
+
},
|
|
220
|
+
rules: {
|
|
221
|
+
"filename-pascal-case": filenamePascalCase,
|
|
222
|
+
"no-multiline-imports": noMultilineImports,
|
|
223
|
+
"sort-imports": sortImports
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// src/configs/recommended.ts
|
|
228
|
+
var recommended = defineConfig([
|
|
229
|
+
globalIgnores(["dist", "src/services/generated", "scripts/types"]),
|
|
230
|
+
{
|
|
231
|
+
files: ["**/*.{ts,tsx}"],
|
|
232
|
+
extends: [js.configs.recommended, tseslint.configs.recommended],
|
|
233
|
+
languageOptions: {
|
|
234
|
+
globals: globals.browser
|
|
235
|
+
},
|
|
236
|
+
plugins: {
|
|
237
|
+
"@stylistic": stylistic,
|
|
238
|
+
"import-x": importX,
|
|
239
|
+
"ai-rules": plugin
|
|
240
|
+
},
|
|
241
|
+
settings: {
|
|
242
|
+
"import-x/resolver-next": [
|
|
243
|
+
createNodeResolver({
|
|
244
|
+
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"]
|
|
245
|
+
})
|
|
246
|
+
]
|
|
247
|
+
},
|
|
248
|
+
rules: {
|
|
249
|
+
"ai-rules/sort-imports": "error",
|
|
250
|
+
"ai-rules/no-multiline-imports": "error",
|
|
251
|
+
"ai-rules/filename-pascal-case": "error",
|
|
252
|
+
"max-len": "off",
|
|
253
|
+
"import-x/no-duplicates": "error",
|
|
254
|
+
"import-x/no-default-export": "off",
|
|
255
|
+
"@stylistic/semi": ["error", "never"],
|
|
256
|
+
"@typescript-eslint/consistent-type-imports": [
|
|
257
|
+
"error",
|
|
258
|
+
{ prefer: "type-imports" }
|
|
259
|
+
],
|
|
260
|
+
"@typescript-eslint/no-unused-vars": [
|
|
261
|
+
"error",
|
|
262
|
+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" }
|
|
263
|
+
],
|
|
264
|
+
"@typescript-eslint/naming-convention": [
|
|
265
|
+
"error",
|
|
266
|
+
{ selector: "interface", format: ["PascalCase"], prefix: ["I"] },
|
|
267
|
+
{ selector: "typeAlias", format: ["PascalCase"], prefix: ["T"] }
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
files: ["**/*.d.ts", "scripts/**/*"],
|
|
273
|
+
rules: {
|
|
274
|
+
"@typescript-eslint/naming-convention": "off"
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
]);
|
|
278
|
+
|
|
279
|
+
// src/index.ts
|
|
280
|
+
var aiGuardPlugin = {
|
|
281
|
+
...plugin,
|
|
282
|
+
configs: {
|
|
283
|
+
recommended
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
var index_default = aiGuardPlugin;
|
|
287
|
+
export {
|
|
288
|
+
index_default as default,
|
|
289
|
+
filenamePascalCase,
|
|
290
|
+
noMultilineImports,
|
|
291
|
+
plugin,
|
|
292
|
+
recommended,
|
|
293
|
+
sortImports
|
|
294
|
+
};
|
|
295
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/configs/recommended.ts","../src/rules/FilenamePascalCase.ts","../src/rules/NoMultilineImports.ts","../src/rules/SortImports.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { importX, createNodeResolver } from 'eslint-plugin-import-x'\nimport { defineConfig, globalIgnores } from 'eslint/config'\nimport stylistic from '@stylistic/eslint-plugin'\nimport tseslint from 'typescript-eslint'\nimport globals from 'globals'\nimport js from '@eslint/js'\n\nimport { plugin } from '../plugin'\n\n\nexport const recommended = defineConfig([\n globalIgnores(['dist', 'src/services/generated', 'scripts/types']),\n {\n files: ['**/*.{ts,tsx}'],\n extends: [js.configs.recommended, tseslint.configs.recommended],\n languageOptions: {\n globals: globals.browser,\n },\n plugins: {\n '@stylistic': stylistic,\n 'import-x': importX,\n 'ai-rules': plugin,\n },\n settings: {\n 'import-x/resolver-next': [\n createNodeResolver({\n extensions: ['.ts', '.tsx', '.d.ts', '.js', '.jsx'],\n }),\n ],\n },\n rules: {\n 'ai-rules/sort-imports': 'error',\n 'ai-rules/no-multiline-imports': 'error',\n 'ai-rules/filename-pascal-case': 'error',\n 'max-len': 'off',\n 'import-x/no-duplicates': 'error',\n 'import-x/no-default-export': 'off',\n '@stylistic/semi': ['error', 'never'],\n '@typescript-eslint/consistent-type-imports': [\n 'error',\n { prefer: 'type-imports' },\n ],\n '@typescript-eslint/no-unused-vars': [\n 'error',\n { argsIgnorePattern: '^_', varsIgnorePattern: '^_' },\n ],\n '@typescript-eslint/naming-convention': [\n 'error',\n { selector: 'interface', format: ['PascalCase'], prefix: ['I'] },\n { selector: 'typeAlias', format: ['PascalCase'], prefix: ['T'] },\n ],\n },\n },\n {\n files: ['**/*.d.ts', 'scripts/**/*'],\n rules: {\n '@typescript-eslint/naming-convention': 'off',\n },\n },\n])\n\nexport default recommended\n","import type { Rule } from 'eslint'\nimport path from 'node:path'\n\n\nexport const filenamePascalCase: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: { description: 'Enforce PascalCase for file names' },\n schema: [],\n messages: {\n invalid: 'File name \"{{basename}}\" must be in PascalCase. Rename to \"{{expected}}\".',\n },\n },\n create(context) {\n const physicalFilename =\n // eslint 9 flat config\n (context as unknown as { getPhysicalFilename?: () => string }).getPhysicalFilename?.() ??\n (context as unknown as { physicalFilename?: string }).physicalFilename ??\n context.filename ??\n ''\n\n const cwd =\n (context as unknown as { getCwd?: () => string }).getCwd?.() ?? process.cwd()\n\n // Normaliza para posix para comparar com src/ e scripts/\n const normalizedPhysical = physicalFilename.split(path.sep).join('/')\n const normalizedCwd = cwd.split(path.sep).join('/')\n\n const relativePath = normalizedPhysical.startsWith(normalizedCwd)\n ? normalizedPhysical.slice(normalizedCwd.length + 1)\n : normalizedPhysical\n\n if (!relativePath.startsWith('src/') && !relativePath.startsWith('scripts/')) return {}\n\n const basename = path.basename(relativePath)\n\n if (basename === 'index.ts' || basename === 'index.tsx' || basename === 'index.js' || basename === 'index.jsx') return {}\n if (basename.endsWith('.d.ts')) return {}\n if (basename.endsWith('.css')) return {}\n\n const ext = path.extname(basename) // .ts\n // Para casos como Component.spec.ts -> ext .ts, nameWithoutExt Component.spec - tratamos mantendo só base antes do primeiro ponto?\n // Mantemos compat com original: remove apenas última extensão .ts/.tsx/.js/.jsx\n const nameWithoutExt = basename.replace(/\\.(ts|tsx|js|jsx)$/, '')\n\n if (!/^[A-Z][a-zA-Z0-9]*$/.test(nameWithoutExt)) {\n const pascalCase = nameWithoutExt\n .split(/[-_]/)\n .map(part => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')\n\n // Preserva extensão original (ex: .tsx)\n const originalExt = basename.slice(nameWithoutExt.length) || ext\n const expected = `${pascalCase}${originalExt}`\n\n context.report({\n loc: { line: 1, column: 0 },\n messageId: 'invalid',\n data: { basename, expected },\n })\n }\n\n return {}\n },\n}\n","import type { Rule } from 'eslint'\n\n\nexport const noMultilineImports: Rule.RuleModule = {\n meta: {\n type: 'layout',\n fixable: 'code',\n docs: {\n description: 'Disallow multiline imports',\n },\n schema: [],\n messages: {\n multilineImport: 'Imports must be written on a single line.',\n },\n },\n\n create(context) {\n const sourceCode = context.sourceCode\n\n return {\n ImportDeclaration(node) {\n const text = sourceCode.getText(node)\n\n if (!text.includes('\\n')) {\n return\n }\n\n context.report({\n node,\n messageId: 'multilineImport',\n\n fix(fixer) {\n const firstToken = sourceCode.getFirstToken(node)\n const lastToken = sourceCode.getLastToken(node)\n\n if (!firstToken || !lastToken) {\n return null\n }\n\n let importText = sourceCode.getText(node)\n\n importText = importText\n .replace(/\\s*\\{\\s*/g, ' { ')\n .replace(/\\s*\\}\\s*/g, ' } ')\n .replace(/\\s*,\\s*/g, ', ')\n .replace(/\\s+/g, ' ')\n .replace(/ \\{ /g, ' { ')\n .replace(/ \\} /g, ' } ')\n .replace(/\\s+from\\s+/g, ' from ')\n .trim()\n // Corrige espaços colapsados em torno de { e }\n .replace(/\\{ \\s+/g, '{ ')\n .replace(/\\s+ \\}/g, ' }')\n\n return fixer.replaceText(node, importText)\n },\n })\n },\n }\n },\n}\n","import type { Rule } from 'eslint'\n\n\nexport const sortImports: Rule.RuleModule = {\n meta: {\n type: 'layout',\n docs: {\n description: 'Sort imports by group and line length descending, collapsing multiline imports',\n },\n fixable: 'code',\n schema: [],\n messages: {\n sortRequired: 'As importações devem estar ordenadas por grupo e tamanho da linha, ocupando uma única linha.',\n },\n },\n create(context) {\n return {\n Program(node) {\n const sourceCode = context.sourceCode\n const content = sourceCode.text\n\n const newContent = getSortedContent(content)\n\n if (newContent && newContent !== content) {\n context.report({\n node,\n messageId: 'sortRequired',\n fix(fixer) {\n return fixer.replaceText(node, newContent)\n },\n })\n }\n },\n }\n },\n}\n\n// ---------------------------------------------------------------------------\n// Tipos auxiliares\n// ---------------------------------------------------------------------------\ntype TImportItem = {\n line: string\n from: string\n}\n\n// ---------------------------------------------------------------------------\n// Lógica Core - exportada para teste e reutilização\n// ---------------------------------------------------------------------------\nexport function getSortedContent(content: string): string | null {\n const collapseMultiline = (match: string) => {\n return match\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n .replace(/\\/\\/.*$/gm, '')\n .replace(/\\s+/g, ' ')\n }\n\n const normalizedContent = content\n .replace(/import\\s+([^'\";]+?)\\s+from\\s+(['\"][^'\"]+['\"])/g, collapseMultiline)\n // Apenas re-exports válidos: export { ... } from / export * from / export * as X from / export type { ... } from\n .replace(/export\\s+(?:type\\s+)?(?:\\{[^}]*\\}|\\*(?:\\s+as\\s+\\w+)?)\\s+from\\s+(['\"][^'\"]+['\"])/g, collapseMultiline)\n\n const lines: string[] = normalizedContent.split('\\n')\n\n const directiveLines: string[] = []\n const reactFirstLine: string[] = []\n const externalLines: TImportItem[] = []\n const internalLines: TImportItem[] = []\n const reExportLines: TImportItem[] = []\n const nonImportLines: string[] = []\n\n let inImportBlock = false\n let canAcceptDirectives = true\n\n for (let i = 0; i < lines.length; i++) {\n const trimmed = lines[i].trim()\n\n if (\n /^(function|const|let|var|class|interface|enum)\\b/.test(trimmed) ||\n (/^(type|export)\\b/.test(trimmed) && !/ from ['\"]/.test(trimmed) && !/^export\\s*\\{[^}]*\\}\\s*from/.test(trimmed) && !/^export\\s*\\*/.test(trimmed)) ||\n trimmed.startsWith('}')\n ) {\n canAcceptDirectives = false\n }\n\n if (inImportBlock && trimmed === '') continue\n\n if (canAcceptDirectives && /^['\"]use (client|server|strict)['\"];?$/.test(trimmed)) {\n directiveLines.push(lines[i])\n continue\n }\n\n const isReExport =\n /^export\\s+(type\\s+)?\\{[^}]*\\}\\s+from\\s+['\"]/.test(trimmed) ||\n /^export\\s+\\*(\\s+as\\s+\\w+)?\\s+from\\s+['\"]/.test(trimmed)\n\n if (isReExport) {\n const m = lines[i].match(/from\\s+['\"]([^'\"]+)['\"]/)\n if (m) reExportLines.push({ line: lines[i], from: m[1] })\n inImportBlock = true\n canAcceptDirectives = false\n continue\n }\n\n const isImport = /^import\\s/.test(trimmed) || /^import\\{/.test(trimmed)\n\n if (isImport) {\n inImportBlock = true\n canAcceptDirectives = false\n\n const fromMatch = lines[i].match(/from\\s+['\"]([^'\"]+)['\"]/)\n const seMatch = lines[i].match(/^import\\s+['\"]([^'\"]+)['\"]/)\n const from = fromMatch ? fromMatch[1] : seMatch ? seMatch[1] : null\n\n if (!from) {\n nonImportLines.push(lines[i])\n continue\n }\n\n const isTypeOnly = /^import\\s+type\\b/.test(trimmed)\n const isInternal = from.startsWith('.') || from.startsWith('@/')\n const isReactEntry = !isTypeOnly && (from === 'react' || from.startsWith('react/'))\n\n if (isReactEntry) {\n reactFirstLine.push(lines[i])\n } else if (isInternal) {\n internalLines.push({ line: lines[i], from })\n } else {\n externalLines.push({ line: lines[i], from })\n }\n continue\n }\n\n inImportBlock = false\n nonImportLines.push(lines[i])\n }\n\n if (reactFirstLine.length === 0 && externalLines.length === 0 && internalLines.length === 0 && reExportLines.length === 0) {\n return null\n }\n\n const byLengthDesc = (a: TImportItem, b: TImportItem) =>\n b.line.length !== a.line.length ? b.line.length - a.line.length : a.line.localeCompare(b.line)\n\n externalLines.sort(byLengthDesc)\n internalLines.sort(byLengthDesc)\n reExportLines.sort(byLengthDesc)\n\n const blocks: string[] = []\n\n if (directiveLines.length > 0) blocks.push(directiveLines.join('\\n'))\n\n const externalBlock = [...reactFirstLine, ...externalLines.map(i => i.line)]\n if (externalBlock.length > 0) {\n if (blocks.length > 0) blocks.push('')\n blocks.push(externalBlock.join('\\n'))\n }\n\n if (internalLines.length > 0) {\n if (blocks.length > 0) blocks.push('')\n blocks.push(internalLines.map(i => i.line).join('\\n'))\n }\n\n if (reExportLines.length > 0) {\n if (blocks.length > 0) blocks.push('')\n blocks.push(reExportLines.map(i => i.line).join('\\n'))\n }\n\n const rest = nonImportLines.join('\\n').replace(/^\\n+/, '')\n\n let newContent: string\n if (blocks.length > 0 && rest.length > 0) {\n newContent = blocks.join('\\n') + '\\n\\n\\n' + rest\n } else if (blocks.length > 0) {\n newContent = blocks.join('\\n') + '\\n'\n } else {\n newContent = rest\n }\n\n return newContent\n}\n","import { filenamePascalCase } from './rules/FilenamePascalCase'\nimport { noMultilineImports } from './rules/NoMultilineImports'\nimport { sortImports } from './rules/SortImports'\n\n\nexport const plugin = {\n meta: {\n name: 'eslint-plugin-ai-rules',\n version: '0.1.0',\n },\n rules: {\n 'filename-pascal-case': filenamePascalCase,\n 'no-multiline-imports': noMultilineImports,\n 'sort-imports': sortImports,\n },\n} as const\n","import { recommended } from './configs/recommended'\nimport { plugin } from './plugin'\n\nexport * from './rules/index'\n\n\nconst aiGuardPlugin = {\n ...plugin,\n configs: {\n recommended,\n },\n}\n\nexport default aiGuardPlugin\nexport { plugin }\nexport { recommended }"],"mappings":";AAAA,SAAS,SAAS,0BAA0B;AAC5C,SAAS,cAAc,qBAAqB;AAC5C,OAAO,eAAe;AACtB,OAAO,cAAc;AACrB,OAAO,aAAa;AACpB,OAAO,QAAQ;;;ACJf,OAAO,UAAU;AAGV,IAAM,qBAAsC;AAAA,EACjD,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM,EAAE,aAAa,oCAAoC;AAAA,IACzD,QAAQ,CAAC;AAAA,IACT,UAAU;AAAA,MACR,SAAS;AAAA,IACX;AAAA,EACF;AAAA,EACA,OAAO,SAAS;AACd,UAAM;AAAA;AAAA,MAEH,QAA8D,sBAAsB,KACpF,QAAqD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AAA,IACP;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-ai-rules",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ESLint plugin com regras úteis para projetos com ESLint - AI Rules",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rm -rf dist",
|
|
21
|
+
"prebuild": "npm run clean",
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"lint": "eslint .",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"verify": "npm run typecheck && npm run lint && npm run build && npm pack --dry-run",
|
|
27
|
+
"prepack": "npm run build",
|
|
28
|
+
"prepublishOnly": "git diff --quiet || (echo '✖ uncommitted changes — commit before publishing' && exit 1) && npm run verify",
|
|
29
|
+
"postpublish": "echo '✔ published. Run: git push --follow-tags'"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"eslint",
|
|
36
|
+
"eslintplugin",
|
|
37
|
+
"eslint-plugin",
|
|
38
|
+
"ai-rules"
|
|
39
|
+
],
|
|
40
|
+
"author": "",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"eslint": "^8.57.0 || ^9.0.0",
|
|
44
|
+
"typescript": ">=5.0.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@eslint/js": "^9.0.0",
|
|
48
|
+
"@stylistic/eslint-plugin": "^5.0.0",
|
|
49
|
+
"eslint-plugin-import-x": "^4.0.0",
|
|
50
|
+
"globals": "^16.0.0",
|
|
51
|
+
"typescript-eslint": "^8.0.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^22.0.0",
|
|
55
|
+
"eslint": "^9.0.0",
|
|
56
|
+
"jiti": "^2.7.0",
|
|
57
|
+
"tsup": "^8.0.0",
|
|
58
|
+
"tsx": "^4.0.0",
|
|
59
|
+
"typescript": "^5.6.0"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=18.0.0"
|
|
63
|
+
}
|
|
64
|
+
}
|