@alien_intelligence/eslint-plugin-nitpicker 0.5.2 → 0.5.3
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 +53 -18
- package/dist/index.js +8 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,20 +70,46 @@ 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/require-context-hook-destructure` | | Require the result of a `use*Context` consumer hook to be destructured. |
|
|
101
|
+
| `nitpicker/require-hook-object-return` | yes | Require a custom hook to return an object rather than a bare function. |
|
|
102
|
+
|
|
103
|
+
### AdonisJS rules
|
|
104
|
+
Shipped by the `adonisjs` config (and `all`).
|
|
105
|
+
| Rule | Fixable | Description |
|
|
106
|
+
|-------------------------------------|---------|-----------------------------------------------------------------------------------|
|
|
107
|
+
| `nitpicker/migration-table-order` | | Group migration table statements as columns, then timestamps, then indexes. |
|
|
108
|
+
| `nitpicker/require-controller-jsdoc`| | Require a JSDoc comment describing an AdonisJS controller (`*Controller` class). |
|
|
109
|
+
| `nitpicker/require-migration-jsdoc` | | Require a JSDoc comment describing an AdonisJS migration. |
|
|
110
|
+
|
|
111
|
+
¹ Only the terminal-period case is auto-fixed; a mid-comment sentence break is reported without a fix so wrapped prose is never mangled.
|
|
112
|
+
² 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
113
|
|
|
88
114
|
### Rule options
|
|
89
115
|
A few rules accept options. Pass them by overriding the rule with a `["warn", { ... }]` tuple.
|
|
@@ -123,6 +149,16 @@ A few rules accept options. Pass them by overriding the rule with a `["warn", {
|
|
|
123
149
|
}
|
|
124
150
|
```
|
|
125
151
|
|
|
152
|
+
`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:
|
|
153
|
+
```js
|
|
154
|
+
{
|
|
155
|
+
files: ["app/**/*.tsx"],
|
|
156
|
+
rules: {
|
|
157
|
+
"nitpicker/no-emojis": ["warn", { allow: ["strings", "templates", "jsx"] }],
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
126
162
|
### Line comment code references
|
|
127
163
|
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
164
|
```js
|
|
@@ -133,14 +169,13 @@ Backticks are left alone in JSDoc and block comments, in tooling directives, whe
|
|
|
133
169
|
### Line comment periods
|
|
134
170
|
`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
171
|
|
|
136
|
-
The two prose cases are
|
|
172
|
+
The two prose cases are handled differently, since removing a period is only safe at the end of a comment:
|
|
137
173
|
```js
|
|
138
174
|
// Reads the token. -> // Reads the token
|
|
139
|
-
// Reads the token. It is cached ->
|
|
140
|
-
// // It is cached
|
|
175
|
+
// Reads the token. It is cached -> reported, not fixed
|
|
141
176
|
const a = 1 // Reads the token. Cached -> reported, not fixed
|
|
142
177
|
```
|
|
143
|
-
A mid-comment period
|
|
178
|
+
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
179
|
|
|
145
180
|
## Framework configs
|
|
146
181
|
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,12 @@
|
|
|
1
|
-
import {ESLintUtils,ASTUtils}from'@typescript-eslint/utils';var
|
|
1
|
+
import {ESLintUtils,ASTUtils}from'@typescript-eslint/utils';var ct={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=ct;var re=ESLintUtils.RuleCreator(()=>`${s.REPO_URL}/blob/main/README.md#rules`);var p=class{toRuleModule(){return re({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 ne(e){return e.parent.type==="ExportDefaultDeclaration"&&e.superClass?.type==="Identifier"&&e.superClass.name==="BaseSchema"}function oe(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 se(e,t){if(e.type!=="ExpressionStatement")return null;let i=ut(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 ut(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 D=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=oe(i);if(r===null)return;let o=0;for(let n of r.body){let a=se(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);}}}}},ae=new D;function le(e){return e.parent.type==="ExportDefaultDeclaration"&&e.id?.name.endsWith("Controller")===true}function f(e){return e.type==="Block"&&e.value.startsWith("*")}function mt(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 S(e,t){let r=e.getCommentsBefore(mt(t)).at(-1);return r!==void 0&&f(r)}function k(e){return /^\s*\*\s*$/.test(e)}function ce(e){return e.match(s.JSDOC.TAG)?.[1]??null}function w(e){return ce(e)!==null}function pe(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 ue(e,t){let i=-1;for(let o=t.loc.start.line+1;o<t.loc.end.line;o++){let n=ce(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(w(e.lines[o-1]??"")){r=o-1;break}return {from:i,to:r}}var A=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){le(i)&&(S(t.sourceCode,i.parent)||t.report({node:i.id??i,messageId:"missingJSDoc"}));}}}},me=new A;var M=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){ne(i)&&(S(t.sourceCode,i.parent)||t.report({node:i.id??i,messageId:"missingJSDoc"}));}}}},de=new M;var fe=250,v=class extends p{name="max-jsdoc-description-length";defaultOptions=[{max:fe}];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??fe;return {Program(){for(let o of t.sourceCode.getAllComments()){if(!f(o))continue;let n=pe(o).length;n<=r||t.report({loc:o.loc,messageId:"tooLong",data:{length:n,max:r}});}}}}},ge=new v;function x(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 ye(e){return x(e)!==null}function R(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 Se(e,t){for(let i of e)if(t===i||t.startsWith(`${i}.`))return true;return false}function he(e){return e.properties.length===0?false:e.properties.every(t=>t.type==="Property"&&t.shorthand&&!t.computed&&t.value.type==="Identifier")}var F=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&&(R(t.sourceCode.getScope(i),i.init.name)||t.report({node:i,messageId:"alias",data:{name:i.id.name,source:i.init.name}})));}}}},Te=new F;var be={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 Ee(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 j(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 P(e,t){return e===e.toUpperCase()?t.toUpperCase():e.charAt(0)===e.charAt(0).toUpperCase()?t.charAt(0).toUpperCase()+t.slice(1):t}function xe(e){return e!==void 0&&s.WORDS.WORD_CHAR.test(e)}var _=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=Ee(be,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 j(o.name)){let a=r[n.text.toLowerCase()];a!==void 0&&t.report({node:o,messageId:"british",data:{british:n.text,american:P(n.text,a)}});}},Program(){for(let o of t.sourceCode.getAllComments())for(let n of j(o.value)){let a=r[n.text.toLowerCase()];if(a===void 0)continue;let m=P(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:lt=>lt.replaceTextRange([d,g],m)});}}}}},Re=new _;function Oe(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 ft(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 Le(e,t){let i=e.replace(/\\/g,"/");return t.some(r=>ft(r).test(i))}var J=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&&Le(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||!Oe(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"});}}}}}},Ce=new J;var gt={strings:"String",templates:"Template",jsx:"JSXText"};function O(e,t){let i=new Set(t),r=[];if(i.size===0)return r;let o=new Set([...i].map(n=>gt[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 z=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=O(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"}));}}}},Ie=new z;var B=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=O(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]}});}}}},Ne=new B;var U=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||!k(o))continue;let n=r;for(;n<i.loc.end.line&&k(t.sourceCode.lines[n]??"");)n++;let a=t.sourceCode.lines[n];if(a!==void 0&&w(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;}}}}},De=new U;function b(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 ke(e){return e.parent?.type==="Program"}function we(e){return e.type==="ArrowFunctionExpression"&&e.params.length===0&&e.body.type==="ImportExpression"}function C(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 h(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)&&h(m,t,i))return true}}return false}function yt(e,t){return e.type==="ArrowFunctionExpression"&&e.body.type!=="BlockStatement"?true:h(e.body,t,i=>i!==null)}function St(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 Ae(e,t){return e.returnType?St(e.returnType):!yt(e,t)}var W=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=ue(t.sourceCode,n);if(a===null||!Ae(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,b(r));},VariableDeclarator(r){(r.init?.type==="ArrowFunctionExpression"||r.init?.type==="FunctionExpression")&&i(r.init,b(r.init));},MethodDefinition(r){r.value.type==="FunctionExpression"&&i(r.value,r);}}}},Me=new W;function I(e){return s.COMMENTS.DIRECTIVE.test(e.value)}function ve(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 Fe(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)||ht(e.value.slice(0,o+1))||t.push({index:i+o,terminal:a.trim()===""});}return t}function je(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 ht(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===""||!xe(r)})}var V=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"||I(i)))for(let r of je(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],'"')]});}}}},Pe=new V;var $=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 Fe(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 $;var G=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=x(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=x(n.init);if(a===null)return;let m=a.slice(0,a.indexOf("."));m!=="this"&&R(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)Se(r,n.path)||t.report({node:n.node,messageId:"propertyAccessAlias",data:{name:n.name,expression:n.expression}});}}}},Je=new G;var K=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"&&!ye(i.init)||he(i.id)&&t.report({node:i,messageId:"destructure",data:{source:t.sourceCode.getText(i.init)}}));}}}},ze=new K;var q=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)}});}}}}},Be=new q;var H=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(I(r)||i(r))continue;let o=ve(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())});}}}}},Ue=new H;var We={adonisjs:"AdonisJS",react:"React"};function Tt(e){let t=[];for(let i of e.ast.body)i.type==="ImportDeclaration"&&t.push(String(i.source.value));return t}function Ve(e,t){let i=new Set,r=Tt(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 X=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=Ve(t.sourceCode,t.filename);for(let m of a)r.has(m)||o[m]||t.report({node:n,messageId:"missingConfig",data:{framework:We[m],config:m}});}}}},$e=new X;function Ge(e){return /^[A-Z]/.test(e)}function Ke(e){return s.REACT.HOOK.test(e)}function qe(e){return s.REACT.CONTEXT_HOOK.test(e)}function Y(e){return e?e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"?true:e.type==="CallExpression"&&e.callee.type==="Identifier"&&e.callee.name==="useCallback":false}function y(e){if(!e)return false;switch(e.type){case "JSXElement":case "JSXFragment":return true;case "ConditionalExpression":return y(e.consequent)||y(e.alternate);case "LogicalExpression":return y(e.left)||y(e.right);case "SequenceExpression":return y(e.expressions.at(-1));default:return false}}function He(e,t){return e.type==="ArrowFunctionExpression"&&e.body.type!=="BlockStatement"?y(e.body):h(e.body,t,y)}var Z=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=C(r);if(n===void 0)return;let a=b(r);ke(a)&&(we(r)||Ge(n)&&He(r,t.sourceCode.visitorKeys)||S(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));}}}},Xe=new Z;function Ye(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 Q=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,Ye(t.sourceCode,n,o))});}}}},Ze=new Q;var ee=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}});}}}},Qe=new ee;var te=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(Y(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"&&Y(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=C(n);if(!(a===void 0||!Ke(a))){if(n.type==="ArrowFunctionExpression"&&n.body.type!=="BlockStatement"){i(n.body)&&r(n.body);return}h(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);}}}},et=new te;var Et=[ae,me,de,ge,Te,Re,Ce,Ie,Ne,De,Me,Pe,_e,Je,ze,Be,Ue,$e,Xe,Ze,Qe,et],E=Object.fromEntries(Et.map(e=>[e.name,e.toRuleModule()]));function T(e){let t={};for(let[i,r]of Object.entries(E))(r.meta.docs?.category??"base")===e&&(t[`${s.PLUGIN_NAME}/${i}`]="warn");return t}function tt(){let e={};for(let t of Object.keys(E))e[`${s.PLUGIN_NAME}/${t}`]="warn";return e}function it(e){return {name:`${s.PLUGIN_NAME}/all`,plugins:{[s.PLUGIN_NAME]:e},settings:{[s.PLUGIN_NAME]:{adonisjs:true,react:true}},rules:tt()}}function N(e){return {name:`${s.PLUGIN_NAME}/base`,plugins:{[s.PLUGIN_NAME]:e},rules:T("base")}}function rt(e){return {...N(e),name:`${s.PLUGIN_NAME}/recommended`}}var xt=["**/start/routes.ts","**/start/routes/**/*.ts"];function nt(e){return {name:`${s.PLUGIN_NAME}/adonisjs`,plugins:{[s.PLUGIN_NAME]:e},settings:{[s.PLUGIN_NAME]:{adonisjs:true}},rules:{...T("adonisjs"),[`${s.PLUGIN_NAME}/no-decorative-comment-separators`]:["warn",{allowIn:xt}]}}}function ot(e){return {name:`${s.PLUGIN_NAME}/react`,plugins:{[s.PLUGIN_NAME]:e},settings:{[s.PLUGIN_NAME]:{react:true}},rules:T("react")}}function st(e){return {base:N(e),recommended:rt(e),adonisjs:nt(e),react:ot(e),all:it(e)}}var at="0.5.3";var ie={meta:{name:`eslint-plugin-${s.PLUGIN_NAME}`,version:at},rules:E,configs:{}};ie.configs=st(ie);var Ko=ie;export{Ko as default};//# sourceMappingURL=index.js.map
|
|
13
12
|
//# sourceMappingURL=index.js.map
|