@alien_intelligence/eslint-plugin-nitpicker 0.5.2 → 0.6.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/README.md +56 -18
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,20 +70,49 @@ Nitpicker ships five shared flat configs:
|
|
|
70
70
|
| `adonisjs` | Opts into the AdonisJS ruleset, and relaxes decorative separators in `start/routes` files. |
|
|
71
71
|
|
|
72
72
|
## Rules
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
|
77
|
-
|
|
78
|
-
| `nitpicker/
|
|
79
|
-
| `nitpicker/no-
|
|
80
|
-
| `nitpicker/no-
|
|
81
|
-
| `nitpicker/no-
|
|
82
|
-
| `nitpicker/no-
|
|
83
|
-
| `nitpicker/no-
|
|
84
|
-
| `nitpicker/no-
|
|
85
|
-
| `nitpicker/
|
|
86
|
-
| `nitpicker/
|
|
73
|
+
The **base** rules are the universal ruleset shipped by `recommended`; the **React** and **AdonisJS** rules ship only in their framework configs. Every rule is enabled as a warning. The Fixable column marks rules that `eslint --fix` can resolve automatically.
|
|
74
|
+
|
|
75
|
+
### Base rules
|
|
76
|
+
| Rule | Fixable | Description |
|
|
77
|
+
|----------------------------------------------|---------|----------------------------------------------------------------------------------------------------|
|
|
78
|
+
| `nitpicker/max-jsdoc-description-length` | | Enforce a maximum character length for a JSDoc description (default 250). |
|
|
79
|
+
| `nitpicker/no-alias-variables` | | Disallow a `const` whose whole value is another variable; use the source directly. |
|
|
80
|
+
| `nitpicker/no-british-english` | yes | Disallow British spellings in identifiers and comments, reporting the American equivalent. |
|
|
81
|
+
| `nitpicker/no-decorative-comment-separators` | | Disallow decorative separators (banners, box-drawing, repeated dashes) inside comments. |
|
|
82
|
+
| `nitpicker/no-em-dash` | | Disallow the em dash (—) character anywhere in the source (`allow` option for copy). |
|
|
83
|
+
| `nitpicker/no-emojis` | | Disallow emoji anywhere in the source (`allow` option for copy). Reported, never auto-removed. |
|
|
84
|
+
| `nitpicker/no-jsdoc-blank-before-tags` | yes | Disallow blank lines before JSDoc tags such as `@param` or `@returns`. |
|
|
85
|
+
| `nitpicker/no-jsdoc-returns-on-void` | yes | Disallow a JSDoc `@returns` tag on a function that returns nothing. |
|
|
86
|
+
| `nitpicker/no-line-comment-backticks` | yes | Disallow backticks in `//` line comments; use double quotes for code references. |
|
|
87
|
+
| `nitpicker/no-line-comment-period` | yes¹ | Disallow prose periods in `//` line comments (code dots, quoted spans, ellipses, `e.g.` are OK). |
|
|
88
|
+
| `nitpicker/no-property-access-alias` | | Disallow a `const` whose whole value is a single property access; inline the expression instead. |
|
|
89
|
+
| `nitpicker/no-property-destructuring` | | Disallow shorthand destructuring off a plain object reference; access the property directly. |
|
|
90
|
+
| `nitpicker/no-single-line-jsdoc` | yes | Require JSDoc comments to span multiple lines rather than a single line. |
|
|
91
|
+
| `nitpicker/require-capitalized-comments` | yes | Require a comment to start with an uppercase letter. |
|
|
92
|
+
| `nitpicker/require-framework-config` | | Warn when a file uses a framework whose Nitpicker config is not enabled. |
|
|
93
|
+
| `nitpicker/require-function-jsdoc` | | Require a JSDoc comment on top-level functions (React components and lazy `import` thunks exempt). |
|
|
94
|
+
| `nitpicker/require-multiline-object` | yes² | Require an object literal with more than a few properties (default 2) to span multiple lines. |
|
|
95
|
+
|
|
96
|
+
### React rules
|
|
97
|
+
Shipped by the `react` config (and `all`).
|
|
98
|
+
| Rule | Fixable | Description |
|
|
99
|
+
|----------------------------------------------|---------|----------------------------------------------------------------------------------------------|
|
|
100
|
+
| `nitpicker/no-jsx-comments` | | Disallow inline `{/* ... */}` comments inside JSX; extract a named sub-component. |
|
|
101
|
+
| `nitpicker/require-context-hook-destructure` | | Require the result of a `use*Context` consumer hook to be destructured. |
|
|
102
|
+
| `nitpicker/require-derived-usememo` | | Require a derived value (built via a non-hook call) in a component or hook to use `useMemo`. |
|
|
103
|
+
| `nitpicker/require-hook-object-return` | yes | Require a custom hook to return an object rather than a bare function. |
|
|
104
|
+
| `nitpicker/require-memo-callback-jsdoc` | | Require a JSDoc on a `useMemo`/`useCallback` (with an `@param` per `useCallback` parameter). |
|
|
105
|
+
|
|
106
|
+
### AdonisJS rules
|
|
107
|
+
Shipped by the `adonisjs` config (and `all`).
|
|
108
|
+
| Rule | Fixable | Description |
|
|
109
|
+
|-------------------------------------|---------|----------------------------------------------------------------------------------|
|
|
110
|
+
| `nitpicker/migration-table-order` | | Group migration table statements as columns, then timestamps, then indexes. |
|
|
111
|
+
| `nitpicker/require-controller-jsdoc`| | Require a JSDoc comment describing an AdonisJS controller (`*Controller` class). |
|
|
112
|
+
| `nitpicker/require-migration-jsdoc` | | Require a JSDoc comment describing an AdonisJS migration. |
|
|
113
|
+
|
|
114
|
+
¹ Only the terminal-period case is auto-fixed; a mid-comment sentence break is reported without a fix so wrapped prose is never mangled.
|
|
115
|
+
² Auto-fixed only when the object holds no comments; an object with an inline comment is reported without a fix so the comment is never dropped.
|
|
87
116
|
|
|
88
117
|
### Rule options
|
|
89
118
|
A few rules accept options. Pass them by overriding the rule with a `["warn", { ... }]` tuple.
|
|
@@ -123,6 +152,16 @@ A few rules accept options. Pass them by overriding the rule with a `["warn", {
|
|
|
123
152
|
}
|
|
124
153
|
```
|
|
125
154
|
|
|
155
|
+
`no-emojis` takes the same `{ allow: ("strings" | "templates" | "jsx" | "comments")[] }` option, for the same reason: an emoji is often deliberate copy or a meaningful marker (a `⚠️` above a risky call). It defaults to `[]`, and it is report-only, never auto-removing a glyph, so an emoji is only ever flagged, not silently deleted:
|
|
156
|
+
```js
|
|
157
|
+
{
|
|
158
|
+
files: ["app/**/*.tsx"],
|
|
159
|
+
rules: {
|
|
160
|
+
"nitpicker/no-emojis": ["warn", { allow: ["strings", "templates", "jsx"] }],
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
126
165
|
### Line comment code references
|
|
127
166
|
A backtick renders as code inside a JSDoc block, but in a `//` comment it is just a literal character, so `no-line-comment-backticks` rewrites those references with double quotes:
|
|
128
167
|
```js
|
|
@@ -133,14 +172,13 @@ Backticks are left alone in JSDoc and block comments, in tooling directives, whe
|
|
|
133
172
|
### Line comment periods
|
|
134
173
|
`no-line-comment-period` only treats a dot as prose when whitespace or the end of the comment follows it, so dots inside code (`foo.bar`, `subagent.*`, `split(".")`), inside a quoted or back-ticked span, in an ellipsis, or closing an abbreviation (`e.g.`, `i.e.`, `etc.`) are left alone.
|
|
135
174
|
|
|
136
|
-
The two prose cases are
|
|
175
|
+
The two prose cases are handled differently, since removing a period is only safe at the end of a comment:
|
|
137
176
|
```js
|
|
138
177
|
// Reads the token. -> // Reads the token
|
|
139
|
-
// Reads the token. It is cached ->
|
|
140
|
-
// // It is cached
|
|
178
|
+
// Reads the token. It is cached -> reported, not fixed
|
|
141
179
|
const a = 1 // Reads the token. Cached -> reported, not fixed
|
|
142
180
|
```
|
|
143
|
-
A mid-comment period
|
|
181
|
+
Only a terminal period is auto-fixed. A mid-comment period runs two fragments together, and auto-splitting it onto a new line mangles wrapped prose paragraphs, so that case is reported for a human or agent to reword rather than fixed.
|
|
144
182
|
|
|
145
183
|
## Framework configs
|
|
146
184
|
Some conventions only make sense for a given framework. Nitpicker detects when a file uses React or AdonisJS and, through `require-framework-config`, nudges you to opt into the matching config for those files. Opting in silences that nudge and applies any framework-specific tweaks.
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {ESLintUtils,ASTUtils}from'@typescript-eslint/utils';var
|
|
1
|
+
import {ESLintUtils,ASTUtils}from'@typescript-eslint/utils';var Tt={PLUGIN_NAME:"nitpicker",REPO_URL:"https://github.com/Alien-Intelligence/eslint-plugin-nitpicker",EM_DASH:"\u2014",EMOJI:new RegExp("\\p{Regional_Indicator}\\p{Regional_Indicator}|\\p{Emoji_Presentation}(?:\\uFE0F|\\p{Emoji_Modifier})?(?:\\u200D\\p{Emoji_Presentation}(?:\\uFE0F|\\p{Emoji_Modifier})?)*|\\p{Extended_Pictographic}\\uFE0F","gu"),COMMENTS:{BOX_DRAWING:/[─-▟]/,PURE_SEPARATOR:/^[-=~*#_+]{3,}$/,WRAPPED_LABEL:/^[-=~*#_+]{2,}\s.*\s[-=~*#_+]{2,}$/,DIRECTIVE:/^\s*(?:eslint\b|eslint-|globals?\b|exported\b|jshint\b|jslint\b|istanbul\b|[cv]8\b|ts-|prettier-ignore|biome-ignore|webpack\b|noinspection\b|@)/,QUOTES:new Set(['"',"`"]),ABBREVIATIONS:["e.g.","i.e.","etc.","vs.","cf.","al.","approx.","resp."]},JSDOC:{TAG:/^\s*\*?\s*@(\w+)/},WORDS:{WORD_CHAR:/[\p{L}\p{N}_$]/u,SUB_WORD:/[A-Z]+(?![a-z])|[A-Z][a-z]+|[a-z]+/g},OBJECTS:{MAX_INLINE_KEYS:2,INDENT_WIDTH:4},FUNCTIONS:{NODE_TYPES:new Set(["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression"])},FRAMEWORKS:{ADONIS_SUBPATH:/^#(models|controllers|services|middleware|validators|policies|config|start|database|providers|lib)\b/,REACT_FILE:/\.[jt]sx$/},REACT:{HOOK:/^use[A-Z]/,CONTEXT_HOOK:/^use[A-Z]\w*Context$/},MIGRATIONS:{INDEX_METHODS:new Set(["index","unique","primary","foreign"]),TIMESTAMP_METHODS:new Set(["timestamp","dateTime","datetime"]),AUDIT_TIMESTAMPS:new Set(["created_at","updated_at","deleted_at"]),CATEGORY_ORDER:["column","timestamp","index"]}},s=Tt;var pe=ESLintUtils.RuleCreator(()=>`${s.REPO_URL}/blob/main/README.md#rules`);var p=class{toRuleModule(){return pe({name:this.name,meta:this.meta,defaultOptions:this.defaultOptions,create:(t,i)=>this.create(t,i)})}};function u({problem:e,why:t,fix:i}){return `${e}
|
|
2
2
|
- why: ${t}
|
|
3
|
-
- fix: ${i}`}function
|
|
4
|
-
`)){let r=i.replace(/^\s*\*? ?/,"").trimEnd();if(r.startsWith("@"))break;t.push(r);}return t.join(" ").replace(/\s+/g," ").trim()}function
|
|
5
|
-
`);for(let
|
|
6
|
-
`)){let o=(r.match(/^\s*\*?\s*/u)?.[0]??"").length,n=r.slice(o).charAt(0);if(n!=="")return {index:t+i+o,char:n};i+=r.length+1;}return null}function
|
|
7
|
-
${o}// `)});}}}}}},Pe=new $;var V=class extends u{name="no-property-access-alias";defaultOptions=[];meta={type:"suggestion",docs:{description:"Disallow a `const` whose whole value is a single property access, inline the expression instead.",recommended:true,category:"base"},schema:[],messages:{propertyAccessAlias:m({problem:"`{{name}}` only aliases the property access `{{expression}}`.",why:"A variable that just renames a property hides where the value comes from when scanning the code",fix:"Remove it and use `{{expression}}` inline, or use `let` if it is reassigned later"})}};create(t){let i=[],r=new Set,o=n=>{if(n.type!=="MemberExpression")return;let s=R(n);s!==null&&r.add(s);};return {AssignmentExpression(n){o(n.left);},UpdateExpression(n){o(n.argument);},VariableDeclarator(n){if(n.parent.type!=="VariableDeclaration"||n.parent.kind!=="const"||n.parent.parent.type==="ExportNamedDeclaration"||n.id.type!=="Identifier"||n.init===null||n.id.typeAnnotation!==void 0)return;let s=R(n.init);if(s===null)return;let l=s.slice(0,s.indexOf("."));l!=="this"&&O(t.sourceCode.getScope(n),l)||i.push({node:n,name:n.id.name,path:s,expression:t.sourceCode.getText(n.init)});},"Program:exit"(){for(let n of i)ye(r,n.path)||t.report({node:n.node,messageId:"propertyAccessAlias",data:{name:n.name,expression:n.expression}});}}}},_e=new V;var G=class extends u{name="no-property-destructuring";defaultOptions=[];meta={type:"suggestion",docs:{description:"Disallow shorthand destructuring off a plain object reference, access the property directly.",recommended:true,category:"base"},schema:[],messages:{destructure:m({problem:"Destructuring from `{{source}}` here just aliases its properties.",why:"Reading `{{source}}.x` at the use site keeps the origin visible, destructuring a plain object hides where a value comes from (destructuring a call or hook result is fine)",fix:"Access the properties on `{{source}}` directly instead of destructuring"})}};create(t){return {VariableDeclarator(i){i.parent.type!=="VariableDeclaration"||i.parent.kind!=="const"||i.parent.parent.type!=="ExportNamedDeclaration"&&(i.id.type!=="ObjectPattern"||i.init===null||i.init.type!=="Identifier"&&!ge(i.init)||Se(i.id)&&t.report({node:i,messageId:"destructure",data:{source:t.sourceCode.getText(i.init)}}));}}}},Je=new G;var K=class extends u{name="no-single-line-jsdoc";defaultOptions=[];meta={type:"layout",fixable:"code",docs:{description:"Require JSDoc comments to span multiple lines rather than sit on a single line.",recommended:true},schema:[],messages:{singleLine:m({problem:"This JSDoc comment is written on a single line.",why:"Multi-line JSDoc is easier to read, diff, and extend with additional tags, and is the house style.",fix:"Put the opening `/**`, the ` * ` content, and the closing `*/` each on their own line."})}};create(t){return {Program(){for(let i of t.sourceCode.getAllComments()){if(!g(i)||i.loc.start.line!==i.loc.end.line)continue;let r=i.value.replace(/^\*/,"").trim();r.length!==0&&t.report({loc:i.loc,messageId:"singleLine",fix(o){let n=" ".repeat(i.loc.start.column),s=`/**
|
|
3
|
+
- fix: ${i}`}function ue(e){return e.parent.type==="ExportDefaultDeclaration"&&e.superClass?.type==="Identifier"&&e.superClass.name==="BaseSchema"}function me(e){if(e.callee.type!=="MemberExpression"||e.callee.property.type!=="Identifier"||e.callee.property.name!=="createTable"||e.callee.object.type!=="MemberExpression"||e.callee.object.property.type!=="Identifier"||e.callee.object.property.name!=="schema")return null;let t=e.arguments.at(-1);return t?.type!=="ArrowFunctionExpression"&&t?.type!=="FunctionExpression"||t.body.type!=="BlockStatement"||t.params[0]?.type!=="Identifier"?null:{body:t.body.body,builderName:t.params[0].name}}function de(e,t){if(e.type!=="ExpressionStatement")return null;let i=Et(e.expression,t);return i===null?null:s.MIGRATIONS.INDEX_METHODS.has(i.method)?"index":i.method==="timestamps"?"timestamp":s.MIGRATIONS.TIMESTAMP_METHODS.has(i.method)?i.firstArgument!==void 0&&s.MIGRATIONS.AUDIT_TIMESTAMPS.has(i.firstArgument)?"timestamp":null:"column"}function Et(e,t){let i=e;for(;i.type==="CallExpression"&&i.callee.type==="MemberExpression";){if(i.callee.object.type==="Identifier"&&i.callee.object.name===t){if(i.callee.property.type!=="Identifier")return null;let r=i.arguments[0],o=r?.type==="Literal"&&typeof r.value=="string"?r.value:void 0;return {method:i.callee.property.name,firstArgument:o}}i=i.callee.object;}return null}var w=class extends p{name="migration-table-order";defaultOptions=[];meta={type:"suggestion",docs:{description:"Group migration table statements as columns, then timestamps, then indexes and constraints.",recommended:true,category:"adonisjs"},schema:[],messages:{outOfOrder:u({problem:"This {{category}} is out of order in the table definition.",why:"A migration reads consistently when columns come first, then timestamps, then indexes and constraints, each grouped together",fix:"Move it into its group so the order stays columns, timestamps, then indexes and constraints"})}};create(t){return {CallExpression(i){let r=me(i);if(r===null)return;let o=0;for(let n of r.body){let a=de(n,r.builderName);if(a===null)continue;let m=s.MIGRATIONS.CATEGORY_ORDER.indexOf(a);m<o&&t.report({node:n,messageId:"outOfOrder",data:{category:a}}),o=Math.max(o,m);}}}}},fe=new w;function ge(e){return e.parent.type==="ExportDefaultDeclaration"&&e.id?.name.endsWith("Controller")===true}function f(e){return e.type==="Block"&&e.value.startsWith("*")}function xt(e){let t=(e.type==="ExportDefaultDeclaration"||e.type==="ExportNamedDeclaration")&&e.declaration!==null?e.declaration:e,r=("decorators"in t?t.decorators:void 0)?.reduce((o,n)=>o===void 0||n.range[0]<o.range[0]?n:o,void 0);return r!==void 0&&r.range[0]<e.range[0]?r:e}function y(e,t){let r=e.getCommentsBefore(xt(t)).at(-1);return r!==void 0&&f(r)}function M(e){return /^\s*\*\s*$/.test(e)}function R(e){return e.match(s.JSDOC.TAG)?.[1]??null}function A(e){return R(e)!==null}function ye(e){let t=[];for(let i of e.value.split(`
|
|
4
|
+
`)){let r=i.replace(/^\s*\*? ?/,"").trimEnd();if(r.startsWith("@"))break;t.push(r);}return t.join(" ").replace(/\s+/g," ").trim()}function Se(e,t){let i=-1;for(let o=t.loc.start.line+1;o<t.loc.end.line;o++){let n=R(e.lines[o-1]??"");if(n==="returns"||n==="return"){i=o;break}}if(i===-1)return null;let r=t.loc.end.line-1;for(let o=i+1;o<t.loc.end.line;o++)if(A(e.lines[o-1]??"")){r=o-1;break}return {from:i,to:r}}var v=class extends p{name="require-controller-jsdoc";defaultOptions=[];meta={type:"suggestion",docs:{description:"Require a JSDoc comment describing an AdonisJS controller.",recommended:true,category:"adonisjs"},schema:[],messages:{missingJSDoc:u({problem:"This controller has no JSDoc describing what it does.",why:"A controller's responsibility should be readable at a glance, before diving into its handler methods",fix:"Add a `/** ... */` JSDoc above the controller class summarizing what it handles"})}};create(t){return {ClassDeclaration(i){ge(i)&&(y(t.sourceCode,i.parent)||t.report({node:i.id??i,messageId:"missingJSDoc"}));}}}},he=new v;var F=class extends p{name="require-migration-jsdoc";defaultOptions=[];meta={type:"suggestion",docs:{description:"Require a JSDoc comment describing an AdonisJS migration.",recommended:true,category:"adonisjs"},schema:[],messages:{missingJSDoc:u({problem:"This migration has no JSDoc describing what it does.",why:"A migration's intent should be readable at a glance, the timestamped filename does not convey the schema change",fix:"Add a `/** ... */` JSDoc above the migration class summarizing the change"})}};create(t){return {ClassDeclaration(i){ue(i)&&(y(t.sourceCode,i.parent)||t.report({node:i.id??i,messageId:"missingJSDoc"}));}}}},Te=new F;var be=250,j=class extends p{name="max-jsdoc-description-length";defaultOptions=[{max:be}];meta={type:"suggestion",docs:{description:"Enforce a maximum character length for a JSDoc description.",recommended:true,category:"base"},schema:[{type:"object",properties:{max:{type:"integer",minimum:1}},additionalProperties:false}],messages:{tooLong:u({problem:"This JSDoc description is {{length}} characters, over the {{max}}-character limit.",why:"A JSDoc description should summarize what something is, an oversized one usually restates the code or explains how it is used, which does not belong here",fix:'Trim it to a concise summary of what it does, and remove any note about how or where it is used (e.g "used by X to ...", "called from Y"), which is an anti-pattern'})}};create(t,i){let r=i[0]?.max??be;return {Program(){for(let o of t.sourceCode.getAllComments()){if(!f(o))continue;let n=ye(o).length;n<=r||t.report({loc:o.loc,messageId:"tooLong",data:{length:n,max:r}});}}}}},Ee=new j;function O(e){let t=[],i=e;for(;;){if(i.type==="ChainExpression"||i.type==="TSNonNullExpression"){i=i.expression;continue}if(i.type==="MemberExpression"){if(i.computed||i.property.type!=="Identifier")return null;t.unshift(i.property.name),i=i.object;continue}break}return t.length===0?null:i.type==="ThisExpression"?["this",...t].join("."):i.type==="Identifier"?[i.name,...t].join("."):null}function xe(e){return O(e)!==null}function C(e,t){let i=ASTUtils.findVariable(e,t);if(i===null)return false;let r=new Set(i.defs.map(o=>o.name));return i.references.some(o=>o.isWrite()&&!r.has(o.identifier))}function Re(e,t){for(let i of e)if(t===i||t.startsWith(`${i}.`))return true;return false}function Oe(e){return e.properties.length===0?false:e.properties.every(t=>t.type==="Property"&&t.shorthand&&!t.computed&&t.value.type==="Identifier")}var P=class extends p{name="no-alias-variables";defaultOptions=[];meta={type:"suggestion",docs:{description:"Disallow a `const` whose whole value is another variable, use the source directly.",recommended:true,category:"base"},schema:[],messages:{alias:u({problem:"`{{name}}` only aliases `{{source}}`.",why:"A variable that just renames another hides the original and adds a name to track for no gain",fix:"Remove it and use `{{source}}` directly, or rename `{{source}}` itself if the new name is better"})}};create(t){return {VariableDeclarator(i){i.parent.type!=="VariableDeclaration"||i.parent.kind!=="const"||i.parent.parent.type!=="ExportNamedDeclaration"&&(i.id.type!=="Identifier"||i.init?.type!=="Identifier"||i.id.typeAnnotation===void 0&&(C(t.sourceCode.getScope(i),i.init.name)||t.report({node:i,messageId:"alias",data:{name:i.id.name,source:i.init.name}})));}}}},Ce=new P;var Ie={colour:"color",colours:"colors",coloured:"colored",colouring:"coloring",behaviour:"behavior",behaviours:"behaviors",favourite:"favorite",favourites:"favorites",flavour:"flavor",flavours:"flavors",honour:"honor",labour:"labor",neighbour:"neighbor",normalise:"normalize",normalised:"normalized",normalising:"normalizing",normalisation:"normalization",initialise:"initialize",initialises:"initializes",initialised:"initialized",initialising:"initializing",initialisation:"initialization",serialise:"serialize",serialised:"serialized",serialising:"serializing",serialisation:"serialization",organise:"organize",organised:"organized",organising:"organizing",organisation:"organization",optimise:"optimize",optimised:"optimized",optimising:"optimizing",optimisation:"optimization",customise:"customize",customised:"customized",customising:"customizing",sanitise:"sanitize",sanitised:"sanitized",sanitising:"sanitizing",synchronise:"synchronize",synchronised:"synchronized",synchronising:"synchronizing",authorise:"authorize",authorised:"authorized",authorising:"authorizing",finalise:"finalize",finalised:"finalized",finalising:"finalizing",capitalise:"capitalize",capitalised:"capitalized",capitalising:"capitalizing",categorise:"categorize",categorised:"categorized",analyse:"analyze",analysed:"analyzed",analysing:"analyzing",centre:"center",centred:"centered",centres:"centers",fibre:"fiber",metre:"meter",licence:"license",defence:"defense",offence:"offense",cancelled:"canceled",cancelling:"canceling",labelled:"labeled",labelling:"labeling",modelling:"modeling",travelled:"traveled",grey:"gray",dialogue:"dialog",catalogue:"catalog"};function Le(e,t,i){let r=Object.create(null);for(let[o,n]of Object.entries(e))r[o.toLowerCase()]=n;for(let[o,n]of Object.entries(t))r[o.toLowerCase()]=n;for(let o of i)delete r[o.toLowerCase()];return r}function _(e){let t=[];for(let i of e.matchAll(s.WORDS.SUB_WORD))i.index!==void 0&&t.push({text:i[0],index:i.index});return t}function J(e,t){return e===e.toUpperCase()?t.toUpperCase():e.charAt(0)===e.charAt(0).toUpperCase()?t.charAt(0).toUpperCase()+t.slice(1):t}function Ne(e){return e!==void 0&&s.WORDS.WORD_CHAR.test(e)}var z=class extends p{name="no-british-english";defaultOptions=[{extra:{},ignore:[]}];meta={type:"suggestion",docs:{description:"Disallow British English spellings in identifiers and comments.",recommended:true,category:"base"},fixable:"code",schema:[{type:"object",properties:{extra:{type:"object",additionalProperties:{type:"string"}},ignore:{type:"array",items:{type:"string"}}},additionalProperties:false}],messages:{british:u({problem:"British spelling `{{british}}`, this codebase uses American English.",why:"One spelling convention keeps identifiers and docs consistent and searchable",fix:"Use `{{american}}` instead"})}};create(t,i){let r=Le(Ie,i[0]?.extra??{},i[0]?.ignore??[]);return {Identifier(o){if(!(o.parent.type==="MemberExpression"&&o.parent.property===o&&!o.parent.computed))for(let n of _(o.name)){let a=r[n.text.toLowerCase()];a!==void 0&&t.report({node:o,messageId:"british",data:{british:n.text,american:J(n.text,a)}});}},Program(){for(let o of t.sourceCode.getAllComments())for(let n of _(o.value)){let a=r[n.text.toLowerCase()];if(a===void 0)continue;let m=J(n.text,a),d=o.range[0]+2+n.index,g=d+n.text.length;t.report({loc:{start:t.sourceCode.getLocFromIndex(d),end:t.sourceCode.getLocFromIndex(g)},messageId:"british",data:{british:n.text,american:m},fix:ht=>ht.replaceTextRange([d,g],m)});}}}}},ke=new z;function De(e){let t=e.replace(/^\s*\*?\s*/,"").trimEnd();return t.length===0?false:s.COMMENTS.BOX_DRAWING.test(t)||s.COMMENTS.PURE_SEPARATOR.test(t)||s.COMMENTS.WRAPPED_LABEL.test(t)}function Ot(e){let t=e.replace(/\\/g,"/"),i="^";for(let r=0;r<t.length;r++){let o=t[r];if(o===void 0)break;o==="*"?t[r+1]==="*"?(i+=".*",r++,t[r+1]==="/"&&r++):i+="[^/]*":"\\^$.|?+()[]{}".includes(o)?i+=`\\${o}`:i+=o;}return new RegExp(`${i}$`)}function we(e,t){let i=e.replace(/\\/g,"/");return t.some(r=>Ot(r).test(i))}var B=class extends p{name="no-decorative-comment-separators";defaultOptions=[{allowIn:[]}];meta={type:"layout",docs:{description:"Disallow decorative separators (banners, box-drawing, repeated dashes) inside comments.",recommended:true,category:"base"},schema:[{type:"object",properties:{allowIn:{type:"array",items:{type:"string"}}},additionalProperties:false}],messages:{decorative:u({problem:"This comment uses a decorative separator.",why:"Repeated separator characters and box-drawing lines are visual noise that add nothing over a plain label",fix:"Remove the separator, a one-line label or a blank line already divides sections clearly"})}};create(t,i){let r=i[0]?.allowIn??[];return r.length>0&&we(t.filename,r)?{}:{Program(){for(let o of t.sourceCode.getAllComments()){let n=o.value.split(`
|
|
5
|
+
`);for(let a=0;a<n.length;a++){let m=n[a];if(m===void 0||!De(m))continue;let d=o.loc.start.line+a,g=t.sourceCode.lines[d-1]??"";t.report({loc:{start:{line:d,column:0},end:{line:d,column:g.length}},messageId:"decorative"});}}}}}},Me=new B;var Ct={strings:"String",templates:"Template",jsx:"JSXText"};function I(e,t){let i=new Set(t),r=[];if(i.size===0)return r;let o=new Set([...i].map(n=>Ct[n]).filter(n=>n!==void 0));for(let n of e.ast.tokens??[])o.has(n.type)&&r.push(n.range);if(i.has("comments"))for(let n of e.getAllComments())r.push(n.range);return r}function L(e,t){return t.some(([i,r])=>e>=i&&e<r)}var U=class extends p{name="no-em-dash";defaultOptions=[{allow:[]}];meta={type:"suggestion",docs:{description:"Disallow the em dash (\u2014) character anywhere in the source.",recommended:true},schema:[{type:"object",properties:{allow:{type:"array",items:{type:"string",enum:["strings","templates","jsx","comments"]}}},additionalProperties:false}],messages:{emDash:u({problem:"Found an em dash (\u2014) character.",why:"Em dashes are typically introduced by AI-generated or auto-formatted text and are discouraged here.",fix:"Replace the em dash with a hyphen (-), a comma (,), or reword the sentence to avoid it, or allow it here with the rule's `allow` option if it is deliberate user-facing copy."})}};create(t,i){return {Program(){let r=t.sourceCode.getText(),o=I(t.sourceCode,i[0]?.allow??[]);for(let n=0;n<r.length;n++)r[n]===s.EM_DASH&&(L(n,o)||t.report({loc:{start:t.sourceCode.getLocFromIndex(n),end:t.sourceCode.getLocFromIndex(n+1)},messageId:"emDash"}));}}}},Ae=new U;var W=class extends p{name="no-emojis";defaultOptions=[{allow:[]}];meta={type:"suggestion",docs:{description:"Disallow emoji characters anywhere in the source.",recommended:true,category:"base"},schema:[{type:"object",properties:{allow:{type:"array",items:{type:"string",enum:["strings","templates","jsx","comments"]}}},additionalProperties:false}],messages:{emoji:u({problem:"Found an emoji ({{emoji}}).",why:"Emojis are usually introduced by AI-generated text and add noise to code, comments, and identifiers",fix:"Remove the emoji, or allow it here with the rule's `allow` option if it is deliberate user-facing copy"})}};create(t,i){return {Program(){let r=t.sourceCode.getText(),o=I(t.sourceCode,i[0]?.allow??[]);for(let n of r.matchAll(s.EMOJI))L(n.index,o)||t.report({loc:{start:t.sourceCode.getLocFromIndex(n.index),end:t.sourceCode.getLocFromIndex(n.index+n[0].length)},messageId:"emoji",data:{emoji:n[0]}});}}}},ve=new W;var V=class extends p{name="no-jsdoc-blank-before-tags";defaultOptions=[];meta={type:"layout",fixable:"code",docs:{description:"Disallow blank lines before JSDoc tags such as `@param` or `@returns`.",recommended:true},schema:[],messages:{blankBeforeTag:u({problem:"There is a blank line before a JSDoc tag.",why:"Tags should follow the description directly; an empty line there is noise that inflates the comment.",fix:"Remove the blank line so the tag follows on directly."})}};create(t){return {Program(){for(let i of t.sourceCode.getAllComments())if(f(i)&&i.loc.start.line!==i.loc.end.line)for(let r=i.loc.start.line;r<=i.loc.end.line;r++){let o=t.sourceCode.lines[r-1];if(o===void 0||!M(o))continue;let n=r;for(;n<i.loc.end.line&&M(t.sourceCode.lines[n]??"");)n++;let a=t.sourceCode.lines[n];if(a!==void 0&&A(a)){let m=t.sourceCode.getIndexFromLoc({line:r,column:0}),d=t.sourceCode.getIndexFromLoc({line:n+1,column:0});t.report({loc:{start:{line:r,column:0},end:{line:n,column:o.length}},messageId:"blankBeforeTag",fix:g=>g.removeRange([m,d])});}r=n;}}}}},Fe=new V;function E(e){let t=e;return t.parent.type==="VariableDeclarator"&&t.parent.parent.type==="VariableDeclaration"&&(t=t.parent.parent),(t.parent.type==="ExportNamedDeclaration"||t.parent.type==="ExportDefaultDeclaration")&&(t=t.parent),t}function je(e){return e.parent?.type==="Program"}function Pe(e){let t=e.parent;for(;t!==void 0;){if(s.FUNCTIONS.NODE_TYPES.has(t.type))return t;t=t.parent;}return null}function _e(e){return e.type==="ArrowFunctionExpression"&&e.params.length===0&&e.body.type==="ImportExpression"}function h(e){if((e.type==="FunctionDeclaration"||e.type==="FunctionExpression")&&e.id)return e.id.name;if(e.parent.type==="VariableDeclarator"&&e.parent.id.type==="Identifier")return e.parent.id.name}function T(e,t,i){if(e.type==="ReturnStatement")return i(e.argument);for(let r of t[e.type]??[]){let o=e[r],n=Array.isArray(o)?o:[o];for(let a of n){let m=a;if(!(!m||typeof m.type!="string")&&!s.FUNCTIONS.NODE_TYPES.has(m.type)&&T(m,t,i))return true}}return false}function It(e,t){return e.type==="ArrowFunctionExpression"&&e.body.type!=="BlockStatement"?true:T(e.body,t,i=>i!==null)}function Lt(e){return e.typeAnnotation.type==="TSVoidKeyword"?true:e.typeAnnotation.type==="TSTypeReference"&&e.typeAnnotation.typeName.type==="Identifier"&&e.typeAnnotation.typeName.name==="Promise"?e.typeAnnotation.typeArguments?.params.length===1&&e.typeAnnotation.typeArguments?.params[0]?.type==="TSVoidKeyword":false}function Je(e,t){return e.returnType?Lt(e.returnType):!It(e,t)}var $=class extends p{name="no-jsdoc-returns-on-void";defaultOptions=[];meta={type:"suggestion",fixable:"code",docs:{description:"Disallow a JSDoc `@returns` tag on a function that returns nothing.",recommended:true,category:"base"},schema:[],messages:{voidReturns:u({problem:"This function returns nothing, but its JSDoc has a `@returns` tag.",why:"A `@returns` on a void function documents a value that never exists and drifts from the code",fix:"Remove the `@returns` tag"})}};create(t){let i=(r,o)=>{let n=t.sourceCode.getCommentsBefore(o).at(-1);if(n===void 0||!f(n))return;let a=Se(t.sourceCode,n);if(a===null||!Je(r,t.sourceCode.visitorKeys))return;let m=t.sourceCode.getIndexFromLoc({line:a.from,column:0}),d=t.sourceCode.getIndexFromLoc({line:a.to+1,column:0});t.report({loc:{start:{line:a.from,column:0},end:{line:a.to,column:(t.sourceCode.lines[a.to-1]??"").length}},messageId:"voidReturns",fix:g=>g.removeRange([m,d])});};return {FunctionDeclaration(r){i(r,E(r));},VariableDeclarator(r){(r.init?.type==="ArrowFunctionExpression"||r.init?.type==="FunctionExpression")&&i(r.init,E(r.init));},MethodDefinition(r){r.value.type==="FunctionExpression"&&i(r.value,r);}}}},ze=new $;function N(e){return s.COMMENTS.DIRECTIVE.test(e.value)}function Be(e){let t=e.range[0]+2;if(e.type==="Line"){let r=e.value.match(/\S/u);return r?.index===void 0?null:{index:t+r.index,char:r[0]}}let i=0;for(let r of e.value.split(`
|
|
6
|
+
`)){let o=(r.match(/^\s*\*?\s*/u)?.[0]??"").length,n=r.slice(o).charAt(0);if(n!=="")return {index:t+i+o,char:n};i+=r.length+1;}return null}function Ue(e){let t=[],i=e.range[0]+2,r=null;for(let o=0;o<e.value.length;o++){let n=e.value.charAt(o);if(r!==null){n===r&&(r=null);continue}if(s.COMMENTS.QUOTES.has(n)&&e.value.includes(n,o+1)){r=n;continue}if(n!==".")continue;if(e.value.charAt(o+1)==="."){for(;e.value.charAt(o+1)===".";)o++;continue}let a=e.value.slice(o+1);a!==""&&!/^\s/u.test(a)||Nt(e.value.slice(0,o+1))||t.push({index:i+o,terminal:a.trim()===""});}return t}function We(e){let t=[],i=e.range[0]+2;for(let r=0;r<e.value.length;r++){if(e.value.charAt(r)!=="`")continue;if(e.value.charAt(r+1)==="`"){for(;e.value.charAt(r+1)==="`";)r++;continue}let o=e.value.indexOf("`",r+1);if(o===-1)break;let n=e.value.slice(r+1,o);n.includes('"')||t.push({start:i+r,end:i+o,text:n}),r=o;}return t}function Nt(e){let t=e.toLowerCase();return s.COMMENTS.ABBREVIATIONS.some(i=>{if(!t.endsWith(i))return false;let r=t.charAt(t.length-i.length-1);return r===""||!Ne(r)})}var G=class extends p{name="no-line-comment-backticks";defaultOptions=[];meta={type:"suggestion",fixable:"code",docs:{description:"Disallow backticks in `//` line comments, use double quotes for code references.",recommended:true,category:"base"},schema:[],messages:{backticks:u({problem:"This line comment wraps `{{text}}` in backticks.",why:"Backticks only render as code inside a JSDoc block, in a `//` comment they stay literal characters, so double quotes read better",fix:'Wrap it in double quotes instead: "{{text}}"'})}};create(t){return {Program(){for(let i of t.sourceCode.getAllComments())if(!(i.type!=="Line"||N(i)))for(let r of We(i))t.report({loc:{start:t.sourceCode.getLocFromIndex(r.start),end:t.sourceCode.getLocFromIndex(r.end+1)},messageId:"backticks",data:{text:r.text},fix:o=>[o.replaceTextRange([r.start,r.start+1],'"'),o.replaceTextRange([r.end,r.end+1],'"')]});}}}},Ve=new G;var K=class extends p{name="no-line-comment-period";defaultOptions=[];meta={type:"layout",fixable:"code",docs:{description:"Disallow prose periods in `//` line comments (code-reference dots and ellipses are allowed).",recommended:true},schema:[],messages:{period:u({problem:"This line comment ends with a period.",why:"Line comments should be short, clear fragments, not full sentences, so a closing period is just noise, dots inside code references like `foo.bar` are allowed.",fix:"Remove the period and keep the comment terse."}),sentence:u({problem:"This line comment runs two sentences together with a period.",why:"Line comments should be short, clear fragments, dropping the period on its own would leave a run-on, so the sentences belong on separate lines",fix:"Split it into one `//` line per fragment, or reword it as a single fragment (reported, not auto-fixed, so wrapped prose is never mangled)"})}};create(t){return {Program(){for(let i of t.sourceCode.getAllComments())if(i.type==="Line")for(let r of Ue(i)){let o={start:t.sourceCode.getLocFromIndex(r.index),end:t.sourceCode.getLocFromIndex(r.index+1)};if(r.terminal){t.report({loc:o,messageId:"period",fix:n=>n.removeRange([r.index,r.index+1])});continue}t.report({loc:o,messageId:"sentence"});}}}}},$e=new K;var q=class extends p{name="no-property-access-alias";defaultOptions=[];meta={type:"suggestion",docs:{description:"Disallow a `const` whose whole value is a single property access, inline the expression instead.",recommended:true,category:"base"},schema:[],messages:{propertyAccessAlias:u({problem:"`{{name}}` only aliases the property access `{{expression}}`.",why:"A variable that just renames a property hides where the value comes from when scanning the code",fix:"Remove it and use `{{expression}}` inline, or use `let` if it is reassigned later"})}};create(t){let i=[],r=new Set,o=n=>{if(n.type!=="MemberExpression")return;let a=O(n);a!==null&&r.add(a);};return {AssignmentExpression(n){o(n.left);},UpdateExpression(n){o(n.argument);},VariableDeclarator(n){if(n.parent.type!=="VariableDeclaration"||n.parent.kind!=="const"||n.parent.parent.type==="ExportNamedDeclaration"||n.id.type!=="Identifier"||n.init===null||n.id.typeAnnotation!==void 0)return;let a=O(n.init);if(a===null)return;let m=a.slice(0,a.indexOf("."));m!=="this"&&C(t.sourceCode.getScope(n),m)||i.push({node:n,name:n.id.name,path:a,expression:t.sourceCode.getText(n.init)});},"Program:exit"(){for(let n of i)Re(r,n.path)||t.report({node:n.node,messageId:"propertyAccessAlias",data:{name:n.name,expression:n.expression}});}}}},Ge=new q;var H=class extends p{name="no-property-destructuring";defaultOptions=[];meta={type:"suggestion",docs:{description:"Disallow shorthand destructuring off a plain object reference, access the property directly.",recommended:true,category:"base"},schema:[],messages:{destructure:u({problem:"Destructuring from `{{source}}` here just aliases its properties.",why:"Reading `{{source}}.x` at the use site keeps the origin visible, destructuring a plain object hides where a value comes from (destructuring a call or hook result is fine)",fix:"Access the properties on `{{source}}` directly instead of destructuring"})}};create(t){return {VariableDeclarator(i){i.parent.type!=="VariableDeclaration"||i.parent.kind!=="const"||i.parent.parent.type!=="ExportNamedDeclaration"&&(i.id.type!=="ObjectPattern"||i.init===null||i.init.type!=="Identifier"&&!xe(i.init)||Oe(i.id)&&t.report({node:i,messageId:"destructure",data:{source:t.sourceCode.getText(i.init)}}));}}}},Ke=new H;var X=class extends p{name="no-single-line-jsdoc";defaultOptions=[];meta={type:"layout",fixable:"code",docs:{description:"Require JSDoc comments to span multiple lines rather than sit on a single line.",recommended:true},schema:[],messages:{singleLine:u({problem:"This JSDoc comment is written on a single line.",why:"Multi-line JSDoc is easier to read, diff, and extend with additional tags, and is the house style.",fix:"Put the opening `/**`, the ` * ` content, and the closing `*/` each on their own line."})}};create(t){return {Program(){for(let i of t.sourceCode.getAllComments()){if(!f(i)||i.loc.start.line!==i.loc.end.line)continue;let r=i.value.replace(/^\*/,"").trim();r.length!==0&&t.report({loc:i.loc,messageId:"singleLine",fix(o){let n=" ".repeat(i.loc.start.column),a=`/**
|
|
8
7
|
${n} * ${r}
|
|
9
|
-
${n} */`;return o.replaceTextRange(i.range,
|
|
10
|
-
${t.properties.map(
|
|
8
|
+
${n} */`;return o.replaceTextRange(i.range,a)}});}}}}},qe=new X;var Y=class extends p{name="require-capitalized-comments";defaultOptions=[];meta={type:"suggestion",fixable:"code",docs:{description:"Require a comment to start with an uppercase letter.",recommended:true,category:"base"},schema:[],messages:{capitalize:u({problem:"This comment starts with a lowercase letter.",why:"A comment reads as a sentence, and a sentence starts with a capital letter",fix:"Capitalize the first letter of the comment"})}};create(t){let i=r=>{if(r.type!=="Line")return false;let o=t.sourceCode.lines[r.loc.start.line-2];return o!==void 0&&/^\s*\/\//.test(o)};return {Program(){for(let r of t.sourceCode.getAllComments()){if(N(r)||i(r))continue;let o=Be(r);o===null||!new RegExp("\\p{Ll}","u").test(o.char)||/^(?:https?:\/\/|www\.)/u.test(t.sourceCode.getText().slice(o.index))||t.report({loc:{start:t.sourceCode.getLocFromIndex(o.index),end:t.sourceCode.getLocFromIndex(o.index+o.char.length)},messageId:"capitalize",fix:n=>n.replaceTextRange([o.index,o.index+o.char.length],o.char.toUpperCase())});}}}}},He=new Y;var Xe={adonisjs:"AdonisJS",react:"React"};function kt(e){let t=[];for(let i of e.ast.body)i.type==="ImportDeclaration"&&t.push(String(i.source.value));return t}function Ye(e,t){let i=new Set,r=kt(e);return r.some(n=>n.startsWith("@adonisjs/")||s.FRAMEWORKS.ADONIS_SUBPATH.test(n))&&i.add("adonisjs"),(r.some(n=>n==="react"||n.startsWith("react/")||n==="react-dom")||s.FRAMEWORKS.REACT_FILE.test(t))&&i.add("react"),i}var Z=class extends p{name="require-framework-config";defaultOptions=[{ignore:[]}];meta={type:"suggestion",docs:{description:"Warn when a file uses a framework whose Nitpicker config is not enabled.",recommended:true,category:"base"},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["adonisjs","react"]}}},additionalProperties:false}],messages:{missingConfig:u({problem:"This file uses {{framework}} but the Nitpicker {{framework}} rules are not enabled.",why:"Framework rules only run when you opt into the matching config, so files like this one go unchecked",fix:"Add `nitpicker.configs.{{config}}` (scoped to these files) to your ESLint config, or turn off `nitpicker/require-framework-config`"})}};create(t,i){let r=new Set(i[0]?.ignore??[]),o=t.settings[s.PLUGIN_NAME]??{};return {Program(n){let a=Ye(t.sourceCode,t.filename);for(let m of a)r.has(m)||o[m]||t.report({node:n,messageId:"missingConfig",data:{framework:Xe[m],config:m}});}}}},Ze=new Z;function Q(e){return /^[A-Z]/.test(e)}function k(e){return s.REACT.HOOK.test(e)}function Qe(e){return s.REACT.CONTEXT_HOOK.test(e)}function ee(e){return e?e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"?true:e.type==="CallExpression"&&e.callee.type==="Identifier"&&e.callee.name==="useCallback":false}function S(e){if(!e)return false;switch(e.type){case "JSXElement":case "JSXFragment":return true;case "ConditionalExpression":return S(e.consequent)||S(e.alternate);case "LogicalExpression":return S(e.left)||S(e.right);case "SequenceExpression":return S(e.expressions.at(-1));default:return false}}function te(e,t){return e.type==="ArrowFunctionExpression"&&e.body.type!=="BlockStatement"?S(e.body):T(e.body,t,S)}function et(e,t){let i=h(e);return i===void 0?false:k(i)||Q(i)&&te(e,t)}function tt(e,t){if(e.type==="CallExpression")return !(e.callee.type==="Identifier"&&k(e.callee.name));for(let i of t[e.type]??[]){let r=e[i],o=Array.isArray(r)?r:[r];for(let n of o){let a=n;if(!(!a||typeof a.type!="string")&&!s.FUNCTIONS.NODE_TYPES.has(a.type)&&tt(a,t))return true}}return false}function it(e,t){return e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"?false:tt(e,t)}var ie=class extends p{name="require-function-jsdoc";defaultOptions=[];meta={type:"suggestion",docs:{description:"Require a JSDoc comment on top-level functions, except React component functions.",recommended:true},schema:[],messages:{missingJSDoc:u({problem:"The function `{{name}}` has no JSDoc comment.",why:"Top-level functions must document their purpose, parameters, and return value, React component functions are the only exception.",fix:"Add a `/** ... */` JSDoc block immediately above the function describing what it does."})}};create(t){let i=(r,o)=>{let n=h(r);if(n===void 0)return;let a=E(r);je(a)&&(_e(r)||Q(n)&&te(r,t.sourceCode.visitorKeys)||y(t.sourceCode,a)||t.report({node:o,messageId:"missingJSDoc",data:{name:n}}));};return {FunctionDeclaration(r){i(r,r.id??r);},VariableDeclarator(r){r.init&&(r.init.type!=="ArrowFunctionExpression"&&r.init.type!=="FunctionExpression"||i(r.init,r.id));}}}},rt=new ie;function nt(e,t,i){let o=(e.lines[t.loc.start.line-1]??"").match(/^\s*/)?.[0]??"",n=o+" ".repeat(i);return `{
|
|
9
|
+
${t.properties.map(m=>`${n}${e.getText(m)}`).join(`,
|
|
11
10
|
`)},
|
|
12
|
-
${o}}`}var
|
|
11
|
+
${o}}`}var re=class extends p{name="require-multiline-object";defaultOptions=[{maxKeys:s.OBJECTS.MAX_INLINE_KEYS,indent:s.OBJECTS.INDENT_WIDTH}];meta={type:"suggestion",fixable:"code",docs:{description:"Require an object literal with more than a few properties to span multiple lines.",recommended:true,category:"base"},schema:[{type:"object",properties:{maxKeys:{type:"integer",minimum:1},indent:{type:"integer",minimum:1}},additionalProperties:false}],messages:{shouldWrap:u({problem:"This object literal has {{count}} properties packed onto a single line.",why:"An object with more than {{max}} properties is easier to scan, diff, and edit when each property sits on its own line",fix:"Break it across multiple lines, one property per line with a trailing comma"})}};create(t,i){let r=i[0]?.maxKeys??s.OBJECTS.MAX_INLINE_KEYS,o=i[0]?.indent??s.OBJECTS.INDENT_WIDTH;return {ObjectExpression(n){if(n.properties.length<=r||n.loc.start.line!==n.loc.end.line)return;let a=t.sourceCode.getCommentsInside(n).length>0;t.report({node:n,messageId:"shouldWrap",data:{count:n.properties.length,max:r},fix:a?null:m=>m.replaceText(n,nt(t.sourceCode,n,o))});}}}},ot=new re;var ne=class extends p{name="no-jsx-comments";defaultOptions=[];meta={type:"suggestion",docs:{description:"Disallow inline `{/* ... */}` comments inside JSX.",recommended:true,category:"react"},schema:[],messages:{jsxComment:u({problem:"This JSX holds an inline `{/* ... */}` comment.",why:"A comment labeling a JSX section is a sign it should be its own named component, JSX should read as structure, not carry prose markers",fix:"Extract the section into a named sub-component whose name says what the comment said, or drop the comment"})}};create(t){return {JSXExpressionContainer(i){i.expression.type==="JSXEmptyExpression"&&t.sourceCode.getCommentsInside(i).length!==0&&t.report({node:i,messageId:"jsxComment"});}}}},st=new ne;var oe=class extends p{name="require-context-hook-destructure";defaultOptions=[];meta={type:"suggestion",docs:{description:"Require the result of a context-consumer hook to be destructured.",recommended:true,category:"react"},schema:[],messages:{destructure:u({problem:"`{{hook}}` is bound whole instead of destructured.",why:"Destructuring at the call site names exactly what the caller uses and reads better than repeated `{{name}}.member` access",fix:"Destructure the members in use, e.g. `const { a, b } = {{hook}}()`"})}};create(t){return {VariableDeclarator(i){i.id.type!=="Identifier"||i.init?.type!=="CallExpression"||i.init.callee.type!=="Identifier"||!Qe(i.init.callee.name)||t.report({node:i,messageId:"destructure",data:{hook:i.init.callee.name,name:i.id.name}});}}}},at=new oe;var se=class extends p{name="require-derived-usememo";defaultOptions=[];meta={type:"suggestion",docs:{description:"Require a derived value in a component or hook to be memoized with useMemo.",recommended:true,category:"react"},schema:[],messages:{useMemo:u({problem:"This derived value is computed inline on every render.",why:"A value derived through a call is recomputed each render and has nowhere to document itself, a useMemo makes it stable and gives it a JSDoc home",fix:"Wrap it in `useMemo(() => ..., [deps])` with a JSDoc describing the value, even for a one-liner"})}};create(t){return {VariableDeclarator(i){if(i.parent.type!=="VariableDeclaration"||i.parent.kind!=="const"||i.id.type!=="Identifier"||i.init===null)return;let r=Pe(i);r===null||!et(r,t.sourceCode.visitorKeys)||it(i.init,t.sourceCode.visitorKeys)&&t.report({node:i,messageId:"useMemo"});}}}},lt=new se;var ae=class extends p{name="require-hook-object-return";defaultOptions=[];meta={type:"suggestion",fixable:"code",docs:{description:"Require a custom hook to return an object rather than a bare function.",recommended:true,category:"react"},schema:[],messages:{wrapInObject:u({problem:"This hook returns a bare function instead of an object.",why:"Returning an object lets the hook expose new members later without changing every call site, a bare function locks its shape",fix:"Return the function inside an object, e.g. `return { handleThing }`"})}};create(t){let i=n=>{if(ee(n))return true;if(n.type!=="Identifier")return false;let m=ASTUtils.findVariable(t.sourceCode.getScope(n),n.name)?.defs.at(-1)?.node;return m?.type==="VariableDeclarator"&&ee(m.init)},r=n=>{t.report({node:n,messageId:"wrapInObject",fix:n.type==="Identifier"?a=>a.replaceText(n,`{ ${n.name} }`):void 0});},o=n=>{let a=h(n);if(!(a===void 0||!k(a))){if(n.type==="ArrowFunctionExpression"&&n.body.type!=="BlockStatement"){i(n.body)&&r(n.body);return}T(n.body,t.sourceCode.visitorKeys,m=>(m!==null&&i(m)&&r(m),false));}};return {FunctionDeclaration(n){o(n);},FunctionExpression(n){o(n);},ArrowFunctionExpression(n){o(n);}}}},ct=new ae;var wt=new Set(["useMemo","useCallback"]),le=class extends p{name="require-memo-callback-jsdoc";defaultOptions=[];meta={type:"suggestion",docs:{description:"Require a JSDoc on a useMemo or useCallback (with an `@param` per useCallback parameter).",recommended:true,category:"react"},schema:[],messages:{missingJSDoc:u({problem:"This `{{hook}}` has no JSDoc.",why:"A memoized value or handler should document what it is, so its purpose is clear without reading the factory",fix:"Add a `/** ... */` JSDoc above the `const`"}),missingParam:u({problem:"This `useCallback`'s JSDoc documents fewer parameters than the callback takes.",why:"A callback is a function, so each parameter it takes should be documented like any other",fix:"Add an `@param` line for each parameter of the callback"})}};create(t){return {VariableDeclarator(i){if(i.init?.type!=="CallExpression"||i.init.callee.type!=="Identifier"||!wt.has(i.init.callee.name))return;let r=i.parent;if(r.parent?.type==="ExportNamedDeclaration"&&(r=r.parent),!y(t.sourceCode,r)){t.report({node:i.id,messageId:"missingJSDoc",data:{hook:i.init.callee.name}});return}if(i.init.callee.name!=="useCallback")return;let o=i.init.arguments[0];if(o?.type!=="ArrowFunctionExpression"&&o?.type!=="FunctionExpression"||o.params.length===0)return;(t.sourceCode.getCommentsBefore(r).at(-1)?.value.split(`
|
|
12
|
+
`)??[]).filter(m=>R(m)==="param").length<o.params.length&&t.report({node:i.id,messageId:"missingParam"});}}}},pt=new le;var Mt=[fe,he,Te,Ee,Ce,ke,Me,Ae,ve,Fe,ze,Ve,$e,Ge,Ke,qe,He,Ze,rt,ot,st,at,lt,ct,pt],x=Object.fromEntries(Mt.map(e=>[e.name,e.toRuleModule()]));function b(e){let t={};for(let[i,r]of Object.entries(x))(r.meta.docs?.category??"base")===e&&(t[`${s.PLUGIN_NAME}/${i}`]="warn");return t}function ut(){let e={};for(let t of Object.keys(x))e[`${s.PLUGIN_NAME}/${t}`]="warn";return e}function mt(e){return {name:`${s.PLUGIN_NAME}/all`,plugins:{[s.PLUGIN_NAME]:e},settings:{[s.PLUGIN_NAME]:{adonisjs:true,react:true}},rules:ut()}}function D(e){return {name:`${s.PLUGIN_NAME}/base`,plugins:{[s.PLUGIN_NAME]:e},rules:b("base")}}function dt(e){return {...D(e),name:`${s.PLUGIN_NAME}/recommended`}}var At=["**/start/routes.ts","**/start/routes/**/*.ts"];function ft(e){return {name:`${s.PLUGIN_NAME}/adonisjs`,plugins:{[s.PLUGIN_NAME]:e},settings:{[s.PLUGIN_NAME]:{adonisjs:true}},rules:{...b("adonisjs"),[`${s.PLUGIN_NAME}/no-decorative-comment-separators`]:["warn",{allowIn:At}]}}}function gt(e){return {name:`${s.PLUGIN_NAME}/react`,plugins:{[s.PLUGIN_NAME]:e},settings:{[s.PLUGIN_NAME]:{react:true}},rules:b("react")}}function yt(e){return {base:D(e),recommended:dt(e),adonisjs:ft(e),react:gt(e),all:mt(e)}}var St="0.6.0";var ce={meta:{name:`eslint-plugin-${s.PLUGIN_NAME}`,version:St},rules:x,configs:{}};ce.configs=yt(ce);var xs=ce;export{xs as default};//# sourceMappingURL=index.js.map
|
|
13
13
|
//# sourceMappingURL=index.js.map
|