@alien_intelligence/eslint-plugin-nitpicker 0.6.2 → 0.7.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 +9 -0
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,6 +76,7 @@ The **base** rules are the universal ruleset shipped by `recommended`; the **Rea
|
|
|
76
76
|
| Rule | Fixable | Description |
|
|
77
77
|
|----------------------------------------------|---------|----------------------------------------------------------------------------------------------------|
|
|
78
78
|
| `nitpicker/max-jsdoc-description-length` | | Enforce a maximum character length for a JSDoc description (default 250). |
|
|
79
|
+
| `nitpicker/catch-error-name` | | Require a `catch` clause to bind its error as `error` (`_error` for an unused binding). |
|
|
79
80
|
| `nitpicker/no-alias-variables` | | Disallow a `const` whose whole value is another variable; use the source directly. |
|
|
80
81
|
| `nitpicker/no-british-english` | yes | Disallow British spellings in identifiers and comments, reporting the American equivalent. |
|
|
81
82
|
| `nitpicker/no-decorative-comment-separators` | | Disallow decorative separators (banners, box-drawing, repeated dashes) inside comments. |
|
|
@@ -87,6 +88,7 @@ The **base** rules are the universal ruleset shipped by `recommended`; the **Rea
|
|
|
87
88
|
| `nitpicker/no-line-comment-period` | yes¹ | Disallow prose periods in `//` line comments (code dots, quoted spans, ellipses, `e.g.` are OK). |
|
|
88
89
|
| `nitpicker/no-property-access-alias` | | Disallow a `const` whose whole value is a single property access; inline the expression instead. |
|
|
89
90
|
| `nitpicker/no-property-destructuring` | | Disallow shorthand destructuring off a plain object reference; access the property directly. |
|
|
91
|
+
| `nitpicker/no-relative-imports` | | Disallow relative (`./`, `../`) import/re-export paths; use the package alias (`allowIn` option). |
|
|
90
92
|
| `nitpicker/no-single-line-jsdoc` | yes | Require JSDoc comments to span multiple lines rather than a single line. |
|
|
91
93
|
| `nitpicker/require-capitalized-comments` | yes | Require a comment to start with an uppercase letter. |
|
|
92
94
|
| `nitpicker/require-framework-config` | | Warn when a file uses a framework whose Nitpicker config is not enabled. |
|
|
@@ -110,6 +112,7 @@ Shipped by the `adonisjs` config (and `all`).
|
|
|
110
112
|
| `nitpicker/migration-table-order` | | Group migration table statements as columns, then timestamps, then indexes. |
|
|
111
113
|
| `nitpicker/require-controller-jsdoc`| | Require a JSDoc comment describing an AdonisJS controller (`*Controller` class). |
|
|
112
114
|
| `nitpicker/require-migration-jsdoc` | | Require a JSDoc comment describing an AdonisJS migration. |
|
|
115
|
+
| `nitpicker/require-validated-request`| | Require request data through `request.validateUsing()`, not raw `request.input/body/qs/all` (`allowIn` option). |
|
|
113
116
|
|
|
114
117
|
¹ 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
118
|
² 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.
|
|
@@ -137,6 +140,12 @@ A few rules accept options. Pass them by overriding the rule with a `["warn", {
|
|
|
137
140
|
}],
|
|
138
141
|
```
|
|
139
142
|
|
|
143
|
+
`no-relative-imports` and `require-validated-request` each take the same `{ allowIn: string[] }`, a list of globs exempt from the rule, for the few files where the pattern is unavoidable (an entrypoint that reaches outside the alias roots, or a passthrough proxy controller that reads the raw request):
|
|
144
|
+
```js
|
|
145
|
+
"nitpicker/no-relative-imports": ["warn", { allowIn: ["**/bin/*.ts"] }],
|
|
146
|
+
"nitpicker/require-validated-request": ["warn", { allowIn: ["**/*_proxy_controller.ts"] }],
|
|
147
|
+
```
|
|
148
|
+
|
|
140
149
|
`require-framework-config` takes `{ ignore: ("adonisjs" | "react")[] }`, the frameworks to skip the nudge for:
|
|
141
150
|
```js
|
|
142
151
|
"nitpicker/require-framework-config": ["warn", { ignore: ["react"] }],
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {ESLintUtils,ASTUtils}from'@typescript-eslint/utils';var
|
|
2
|
-
- why: ${
|
|
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 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 z=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 z;var be=250,F=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 F;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 j=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 j;var Ie={colour:"color",colours:"colors",coloured:"colored",colouring:"coloring",behaviour:"behavior",behaviours:"behaviors",favour:"favor",favours:"favors",favoured:"favored",favouring:"favoring",favourable:"favorable",favourite:"favorite",favourites:"favorites",flavour:"flavor",flavours:"flavors",honour:"honor",honours:"honors",honoured:"honored",honouring:"honoring",labour:"labor",labours:"labors",laboured:"labored",labouring:"laboring",neighbour:"neighbor",neighbours:"neighbors",humour:"humor",humours:"humors",rumour:"rumor",rumours:"rumors",harbour:"harbor",harbours:"harbors",endeavour:"endeavor",endeavours:"endeavors",endeavoured:"endeavored",endeavouring:"endeavoring",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",organises:"organizes",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",synchronisation:"synchronization",authorise:"authorize",authorised:"authorized",authorising:"authorizing",authorisation:"authorization",finalise:"finalize",finalised:"finalized",finalising:"finalizing",capitalise:"capitalize",capitalised:"capitalized",capitalising:"capitalizing",categorise:"categorize",categorises:"categorizes",categorised:"categorized",categorising:"categorizing",categorisation:"categorization",utilise:"utilize",utilises:"utilizes",utilised:"utilized",utilising:"utilizing",utilisation:"utilization",realise:"realize",realises:"realizes",realised:"realized",realising:"realizing",realisation:"realization",recognise:"recognize",recognises:"recognizes",recognised:"recognized",recognising:"recognizing",summarise:"summarize",summarises:"summarizes",summarised:"summarized",summarising:"summarizing",specialise:"specialize",specialises:"specializes",specialised:"specialized",specialising:"specializing",specialisation:"specialization",minimise:"minimize",minimises:"minimizes",minimised:"minimized",minimising:"minimizing",minimisation:"minimization",maximise:"maximize",maximises:"maximizes",maximised:"maximized",maximising:"maximizing",maximisation:"maximization",prioritise:"prioritize",prioritises:"prioritizes",prioritised:"prioritized",prioritising:"prioritizing",prioritisation:"prioritization",standardise:"standardize",standardises:"standardizes",standardised:"standardized",standardising:"standardizing",standardisation:"standardization",harmonise:"harmonize",harmonises:"harmonizes",harmonised:"harmonized",harmonising:"harmonizing",harmonisation:"harmonization",centralise:"centralize",centralises:"centralizes",centralised:"centralized",centralising:"centralizing",centralisation:"centralization",decentralise:"decentralize",decentralises:"decentralizes",decentralised:"decentralized",decentralising:"decentralizing",decentralisation:"decentralization",emphasise:"emphasize",emphasises:"emphasizes",emphasised:"emphasized",emphasising:"emphasizing",visualise:"visualize",visualises:"visualizes",visualised:"visualized",visualising:"visualizing",visualisation:"visualization",analyse:"analyze",analyses:"analyzes",analysed:"analyzed",analysing:"analyzing",paralyse:"paralyze",paralyses:"paralyzes",paralysed:"paralyzed",paralysing:"paralyzing",centre:"center",centred:"centered",centres:"centers",fibre:"fiber",fibres:"fibers",metre:"meter",metres:"meters",litre:"liter",litres:"liters",theatre:"theater",theatres:"theaters",calibre:"caliber",spectre:"specter",spectres:"specters",licence:"license",defence:"defense",offence:"offense",pretence:"pretense",practise:"practice",cancelled:"canceled",cancelling:"canceling",labelled:"labeled",labelling:"labeling",modelled:"modeled",modelling:"modeling",travelled:"traveled",travelling:"traveling",signalled:"signaled",signalling:"signaling",fuelled:"fueled",fuelling:"fueling",marvellous:"marvelous",counsellor:"counselor",fulfil:"fulfill",fulfils:"fulfills",fulfilment:"fulfillment",enrol:"enroll",enrols:"enrolls",enrolment:"enrollment",instalment:"installment",skilful:"skillful",wilful:"willful",dialogue:"dialog",dialogues:"dialogs",catalogue:"catalog",catalogues:"catalogs",analogue:"analog",analogues:"analogs",grey:"gray",artefact:"artifact",artefacts:"artifacts",sceptic:"skeptic",sceptical:"skeptical",programme:"program",programmes:"programs",enquiry:"inquiry",enquiries:"inquiries",aluminium:"aluminum",tyre:"tire",tyres:"tires"};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 P(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 _(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 J=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 P(o.name)){let a=r[n.text.toLowerCase()];a!==void 0&&t.report({node:o,messageId:"british",data:{british:n.text,american:_(n.text,a)}});}},Program(){for(let o of t.sourceCode.getAllComments())for(let n of P(o.value)){let a=r[n.text.toLowerCase()];if(a===void 0)continue;let m=_(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 J;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<
|
|
6
|
-
`)){let
|
|
7
|
-
${
|
|
8
|
-
${
|
|
9
|
-
${
|
|
1
|
+
import {ESLintUtils,ASTUtils}from'@typescript-eslint/utils';var It={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$/,MEMO_HOOKS:new Set(["useMemo","useCallback"])},REQUEST:{RAW_ACCESSORS:new Set(["input","body","qs","all","only","except"])},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"]}},o=It;var fe=ESLintUtils.RuleCreator(()=>`${o.REPO_URL}/blob/main/README.md#rules`);var l=class{toRuleModule(){return fe({name:this.name,meta:this.meta,defaultOptions:this.defaultOptions,create:(e,i)=>this.create(e,i)})}};function p({problem:t,why:e,fix:i}){return `${t}
|
|
2
|
+
- why: ${e}
|
|
3
|
+
- fix: ${i}`}function ge(t){return t.parent.type==="ExportDefaultDeclaration"&&t.superClass?.type==="Identifier"&&t.superClass.name==="BaseSchema"}function ye(t){if(t.callee.type!=="MemberExpression"||t.callee.property.type!=="Identifier"||t.callee.property.name!=="createTable"||t.callee.object.type!=="MemberExpression"||t.callee.object.property.type!=="Identifier"||t.callee.object.property.name!=="schema")return null;let e=t.arguments.at(-1);return e?.type!=="ArrowFunctionExpression"&&e?.type!=="FunctionExpression"||e.body.type!=="BlockStatement"||e.params[0]?.type!=="Identifier"?null:{body:e.body.body,builderName:e.params[0].name}}function Se(t,e){if(t.type!=="ExpressionStatement")return null;let i=Lt(t.expression,e);return i===null?null:o.MIGRATIONS.INDEX_METHODS.has(i.method)?"index":i.method==="timestamps"?"timestamp":o.MIGRATIONS.TIMESTAMP_METHODS.has(i.method)?i.firstArgument!==void 0&&o.MIGRATIONS.AUDIT_TIMESTAMPS.has(i.firstArgument)?"timestamp":null:"column"}function Lt(t,e){let i=t;for(;i.type==="CallExpression"&&i.callee.type==="MemberExpression";){if(i.callee.object.type==="Identifier"&&i.callee.object.name===e){if(i.callee.property.type!=="Identifier")return null;let n=i.arguments[0],s=n?.type==="Literal"&&typeof n.value=="string"?n.value:void 0;return {method:i.callee.property.name,firstArgument:s}}i=i.callee.object;}return null}var M=class extends l{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:p({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(e){return {CallExpression(i){let n=ye(i);if(n===null)return;let s=0;for(let r of n.body){let a=Se(r,n.builderName);if(a===null)continue;let m=o.MIGRATIONS.CATEGORY_ORDER.indexOf(a);m<s&&e.report({node:r,messageId:"outOfOrder",data:{category:a}}),s=Math.max(s,m);}}}}},he=new M;function Te(t){return t.parent.type==="ExportDefaultDeclaration"&&t.id?.name.endsWith("Controller")===true}function f(t){return t.type==="Block"&&t.value.startsWith("*")}function kt(t){let e=(t.type==="ExportDefaultDeclaration"||t.type==="ExportNamedDeclaration")&&t.declaration!==null?t.declaration:t,n=("decorators"in e?e.decorators:void 0)?.reduce((s,r)=>s===void 0||r.range[0]<s.range[0]?r:s,void 0);return n!==void 0&&n.range[0]<t.range[0]?n:t}function y(t,e){let n=t.getCommentsBefore(kt(e)).at(-1);return n!==void 0&&f(n)}function A(t){return /^\s*\*\s*$/.test(t)}function O(t){return t.match(o.JSDOC.TAG)?.[1]??null}function v(t){return O(t)!==null}function be(t){let e=[];for(let i of t.value.split(`
|
|
4
|
+
`)){let n=i.replace(/^\s*\*? ?/,"").trimEnd();if(n.startsWith("@"))break;e.push(n);}return e.join(" ").replace(/\s+/g," ").trim()}function Ee(t,e){let i=-1;for(let s=e.loc.start.line+1;s<e.loc.end.line;s++){let r=O(t.lines[s-1]??"");if(r==="returns"||r==="return"){i=s;break}}if(i===-1)return null;let n=e.loc.end.line-1;for(let s=i+1;s<e.loc.end.line;s++)if(v(t.lines[s-1]??"")){n=s-1;break}return {from:i,to:n}}var z=class extends l{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:p({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(e){return {ClassDeclaration(i){Te(i)&&(y(e.sourceCode,i.parent)||e.report({node:i.id??i,messageId:"missingJSDoc"}));}}}},xe=new z;var F=class extends l{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:p({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(e){return {ClassDeclaration(i){ge(i)&&(y(e.sourceCode,i.parent)||e.report({node:i.id??i,messageId:"missingJSDoc"}));}}}},Re=new F;function Nt(t){let e=t.replace(/\\/g,"/"),i="^";for(let n=0;n<e.length;n++){let s=e[n];if(s===void 0)break;s==="*"?e[n+1]==="*"?(i+=".*",n++,e[n+1]==="/"&&n++):i+="[^/]*":"\\^$.|?+()[]{}".includes(s)?i+=`\\${s}`:i+=s;}return new RegExp(`${i}$`)}function h(t,e){let i=t.replace(/\\/g,"/");return e.some(n=>Nt(n).test(i))}var j=class extends l{name="require-validated-request";defaultOptions=[{allowIn:[]}];meta={type:"suggestion",docs:{description:"Require request data to be read through a Vine validator, not raw request accessors.",recommended:true,category:"adonisjs"},schema:[{type:"object",properties:{allowIn:{type:"array",items:{type:"string"}}},additionalProperties:false}],messages:{rawRead:p({problem:"`request.{{method}}()` reads request data directly.",why:"Request data must pass through a Vine validator so it is typed and checked, a raw accessor bypasses that contract",fix:"Read it through `request.validateUsing(someValidator)` instead"})}};create(e,i){let n=i[0]?.allowIn??[];if(n.length>0&&h(e.filename,n))return {};let s=r=>r.type==="Identifier"?r.name==="request":r.type==="MemberExpression"&&r.property.type==="Identifier"&&r.property.name==="request";return {CallExpression(r){r.callee.type!=="MemberExpression"||r.callee.property.type!=="Identifier"||!o.REQUEST.RAW_ACCESSORS.has(r.callee.property.name)||!s(r.callee.object)||e.report({node:r.callee.property,messageId:"rawRead",data:{method:r.callee.property.name}});}}}},Oe=new j;var P=class extends l{name="catch-error-name";defaultOptions=[];meta={type:"suggestion",docs:{description:"Require a `catch` clause to bind its error as `error`.",recommended:true,category:"base"},schema:[],messages:{rename:p({problem:"This `catch` binds the error as `{{name}}`.",why:"Every catch binds the error as `error` so error handling reads the same across the codebase",fix:"Rename the binding to `error`, or `_error` if it is intentionally unused"})}};create(e){return {CatchClause(i){i.param?.type==="Identifier"&&(i.param.name==="error"||i.param.name.startsWith("_")||e.report({node:i.param,messageId:"rename",data:{name:i.param.name}}));}}}},Ie=new P;var Ce=250,_=class extends l{name="max-jsdoc-description-length";defaultOptions=[{max:Ce}];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:p({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(e,i){let n=i[0]?.max??Ce;return {Program(){for(let s of e.sourceCode.getAllComments()){if(!f(s))continue;let r=be(s).length;r<=n||e.report({loc:s.loc,messageId:"tooLong",data:{length:r,max:n}});}}}}},Le=new _;function I(t){let e=[],i=t;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;e.unshift(i.property.name),i=i.object;continue}break}return e.length===0?null:i.type==="ThisExpression"?["this",...e].join("."):i.type==="Identifier"?[i.name,...e].join("."):null}function ke(t){return I(t)!==null}function C(t,e){let i=ASTUtils.findVariable(t,e);if(i===null)return false;let n=new Set(i.defs.map(s=>s.name));return i.references.some(s=>s.isWrite()&&!n.has(s.identifier))}function Ne(t,e){for(let i of t)if(e===i||e.startsWith(`${i}.`))return true;return false}function De(t){return t.properties.length===0?false:t.properties.every(e=>e.type==="Property"&&e.shorthand&&!e.computed&&e.value.type==="Identifier")}var J=class extends l{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:p({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(e){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(e.sourceCode.getScope(i),i.init.name)||e.report({node:i,messageId:"alias",data:{name:i.id.name,source:i.init.name}})));}}}},we=new J;var Me={colour:"color",colours:"colors",coloured:"colored",colouring:"coloring",behaviour:"behavior",behaviours:"behaviors",favour:"favor",favours:"favors",favoured:"favored",favouring:"favoring",favourable:"favorable",favourite:"favorite",favourites:"favorites",flavour:"flavor",flavours:"flavors",honour:"honor",honours:"honors",honoured:"honored",honouring:"honoring",labour:"labor",labours:"labors",laboured:"labored",labouring:"laboring",neighbour:"neighbor",neighbours:"neighbors",humour:"humor",humours:"humors",rumour:"rumor",rumours:"rumors",harbour:"harbor",harbours:"harbors",endeavour:"endeavor",endeavours:"endeavors",endeavoured:"endeavored",endeavouring:"endeavoring",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",organises:"organizes",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",synchronisation:"synchronization",authorise:"authorize",authorised:"authorized",authorising:"authorizing",authorisation:"authorization",finalise:"finalize",finalised:"finalized",finalising:"finalizing",capitalise:"capitalize",capitalised:"capitalized",capitalising:"capitalizing",categorise:"categorize",categorises:"categorizes",categorised:"categorized",categorising:"categorizing",categorisation:"categorization",utilise:"utilize",utilises:"utilizes",utilised:"utilized",utilising:"utilizing",utilisation:"utilization",realise:"realize",realises:"realizes",realised:"realized",realising:"realizing",realisation:"realization",recognise:"recognize",recognises:"recognizes",recognised:"recognized",recognising:"recognizing",summarise:"summarize",summarises:"summarizes",summarised:"summarized",summarising:"summarizing",specialise:"specialize",specialises:"specializes",specialised:"specialized",specialising:"specializing",specialisation:"specialization",minimise:"minimize",minimises:"minimizes",minimised:"minimized",minimising:"minimizing",minimisation:"minimization",maximise:"maximize",maximises:"maximizes",maximised:"maximized",maximising:"maximizing",maximisation:"maximization",prioritise:"prioritize",prioritises:"prioritizes",prioritised:"prioritized",prioritising:"prioritizing",prioritisation:"prioritization",standardise:"standardize",standardises:"standardizes",standardised:"standardized",standardising:"standardizing",standardisation:"standardization",harmonise:"harmonize",harmonises:"harmonizes",harmonised:"harmonized",harmonising:"harmonizing",harmonisation:"harmonization",centralise:"centralize",centralises:"centralizes",centralised:"centralized",centralising:"centralizing",centralisation:"centralization",decentralise:"decentralize",decentralises:"decentralizes",decentralised:"decentralized",decentralising:"decentralizing",decentralisation:"decentralization",emphasise:"emphasize",emphasises:"emphasizes",emphasised:"emphasized",emphasising:"emphasizing",visualise:"visualize",visualises:"visualizes",visualised:"visualized",visualising:"visualizing",visualisation:"visualization",analyse:"analyze",analyses:"analyzes",analysed:"analyzed",analysing:"analyzing",paralyse:"paralyze",paralyses:"paralyzes",paralysed:"paralyzed",paralysing:"paralyzing",centre:"center",centred:"centered",centres:"centers",fibre:"fiber",fibres:"fibers",metre:"meter",metres:"meters",litre:"liter",litres:"liters",theatre:"theater",theatres:"theaters",calibre:"caliber",spectre:"specter",spectres:"specters",licence:"license",defence:"defense",offence:"offense",pretence:"pretense",practise:"practice",cancelled:"canceled",cancelling:"canceling",labelled:"labeled",labelling:"labeling",modelled:"modeled",modelling:"modeling",travelled:"traveled",travelling:"traveling",signalled:"signaled",signalling:"signaling",fuelled:"fueled",fuelling:"fueling",marvellous:"marvelous",counsellor:"counselor",fulfil:"fulfill",fulfils:"fulfills",fulfilment:"fulfillment",enrol:"enroll",enrols:"enrolls",enrolment:"enrollment",instalment:"installment",skilful:"skillful",wilful:"willful",dialogue:"dialog",dialogues:"dialogs",catalogue:"catalog",catalogues:"catalogs",analogue:"analog",analogues:"analogs",grey:"gray",artefact:"artifact",artefacts:"artifacts",sceptic:"skeptic",sceptical:"skeptical",programme:"program",programmes:"programs",enquiry:"inquiry",enquiries:"inquiries",aluminium:"aluminum",tyre:"tire",tyres:"tires"};function Ae(t,e,i){let n=Object.create(null);for(let[s,r]of Object.entries(t))n[s.toLowerCase()]=r;for(let[s,r]of Object.entries(e))n[s.toLowerCase()]=r;for(let s of i)delete n[s.toLowerCase()];return n}function U(t){let e=[];for(let i of t.matchAll(o.WORDS.SUB_WORD))i.index!==void 0&&e.push({text:i[0],index:i.index});return e}function B(t,e){return t===t.toUpperCase()?e.toUpperCase():t.charAt(0)===t.charAt(0).toUpperCase()?e.charAt(0).toUpperCase()+e.slice(1):e}function ve(t){return t!==void 0&&o.WORDS.WORD_CHAR.test(t)}var W=class extends l{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:p({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(e,i){let n=Ae(Me,i[0]?.extra??{},i[0]?.ignore??[]);return {Identifier(s){if(!(s.parent.type==="MemberExpression"&&s.parent.property===s&&!s.parent.computed))for(let r of U(s.name)){let a=n[r.text.toLowerCase()];a!==void 0&&e.report({node:s,messageId:"british",data:{british:r.text,american:B(r.text,a)}});}},Program(){for(let s of e.sourceCode.getAllComments())for(let r of U(s.value)){let a=n[r.text.toLowerCase()];if(a===void 0)continue;let m=B(r.text,a),d=s.range[0]+2+r.index,g=d+r.text.length;e.report({loc:{start:e.sourceCode.getLocFromIndex(d),end:e.sourceCode.getLocFromIndex(g)},messageId:"british",data:{british:r.text,american:m},fix:Ot=>Ot.replaceTextRange([d,g],m)});}}}}},ze=new W;function Fe(t){let e=t.replace(/^\s*\*?\s*/,"").trimEnd();return e.length===0?false:o.COMMENTS.BOX_DRAWING.test(e)||o.COMMENTS.PURE_SEPARATOR.test(e)||o.COMMENTS.WRAPPED_LABEL.test(e)}var q=class extends l{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:p({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(e,i){let n=i[0]?.allowIn??[];return n.length>0&&h(e.filename,n)?{}:{Program(){for(let s of e.sourceCode.getAllComments()){let r=s.value.split(`
|
|
5
|
+
`);for(let a=0;a<r.length;a++){let m=r[a];if(m===void 0||!Fe(m))continue;let d=s.loc.start.line+a,g=e.sourceCode.lines[d-1]??"";e.report({loc:{start:{line:d,column:0},end:{line:d,column:g.length}},messageId:"decorative"});}}}}}},je=new q;var wt={strings:"String",templates:"Template",jsx:"JSXText"};function L(t,e){let i=new Set(e),n=[];if(i.size===0)return n;let s=new Set([...i].map(r=>wt[r]).filter(r=>r!==void 0));for(let r of t.ast.tokens??[])s.has(r.type)&&n.push(r.range);if(i.has("comments"))for(let r of t.getAllComments())n.push(r.range);return n}function k(t,e){return e.some(([i,n])=>t>=i&&t<n)}var V=class extends l{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:p({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(e,i){return {Program(){let n=e.sourceCode.getText(),s=L(e.sourceCode,i[0]?.allow??[]);for(let r=0;r<n.length;r++)n[r]===o.EM_DASH&&(k(r,s)||e.report({loc:{start:e.sourceCode.getLocFromIndex(r),end:e.sourceCode.getLocFromIndex(r+1)},messageId:"emDash"}));}}}},Pe=new V;var G=class extends l{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:p({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(e,i){return {Program(){let n=e.sourceCode.getText(),s=L(e.sourceCode,i[0]?.allow??[]);for(let r of n.matchAll(o.EMOJI))k(r.index,s)||e.report({loc:{start:e.sourceCode.getLocFromIndex(r.index),end:e.sourceCode.getLocFromIndex(r.index+r[0].length)},messageId:"emoji",data:{emoji:r[0]}});}}}},_e=new G;var K=class extends l{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:p({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(e){return {Program(){for(let i of e.sourceCode.getAllComments())if(f(i)&&i.loc.start.line!==i.loc.end.line)for(let n=i.loc.start.line;n<=i.loc.end.line;n++){let s=e.sourceCode.lines[n-1];if(s===void 0||!A(s))continue;let r=n;for(;r<i.loc.end.line&&A(e.sourceCode.lines[r]??"");)r++;let a=e.sourceCode.lines[r];if(a!==void 0&&v(a)){let m=e.sourceCode.getIndexFromLoc({line:n,column:0}),d=e.sourceCode.getIndexFromLoc({line:r+1,column:0});e.report({loc:{start:{line:n,column:0},end:{line:r,column:s.length}},messageId:"blankBeforeTag",fix:g=>g.removeRange([m,d])});}n=r;}}}}},Je=new K;function x(t){let e=t;return e.parent.type==="VariableDeclarator"&&e.parent.parent.type==="VariableDeclaration"&&(e=e.parent.parent),(e.parent.type==="ExportNamedDeclaration"||e.parent.type==="ExportDefaultDeclaration")&&(e=e.parent),e}function Ue(t){return t.parent?.type==="Program"}function Be(t){let e=t.parent;for(;e!==void 0;){if(o.FUNCTIONS.NODE_TYPES.has(e.type))return e;e=e.parent;}return null}function We(t){return t.type==="ArrowFunctionExpression"&&t.params.length===0&&t.body.type==="ImportExpression"}function T(t){if((t.type==="FunctionDeclaration"||t.type==="FunctionExpression")&&t.id)return t.id.name;if(t.parent.type==="VariableDeclarator"&&t.parent.id.type==="Identifier")return t.parent.id.name}function b(t,e,i){if(t.type==="ReturnStatement")return i(t.argument);for(let n of e[t.type]??[]){let s=t[n],r=Array.isArray(s)?s:[s];for(let a of r){let m=a;if(!(!m||typeof m.type!="string")&&!o.FUNCTIONS.NODE_TYPES.has(m.type)&&b(m,e,i))return true}}return false}function Mt(t,e){return t.type==="ArrowFunctionExpression"&&t.body.type!=="BlockStatement"?true:b(t.body,e,i=>i!==null)}function At(t){return t.typeAnnotation.type==="TSVoidKeyword"?true:t.typeAnnotation.type==="TSTypeReference"&&t.typeAnnotation.typeName.type==="Identifier"&&t.typeAnnotation.typeName.name==="Promise"?t.typeAnnotation.typeArguments?.params.length===1&&t.typeAnnotation.typeArguments?.params[0]?.type==="TSVoidKeyword":false}function qe(t,e){return t.returnType?At(t.returnType):!Mt(t,e)}var $=class extends l{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:p({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(e){let i=(n,s)=>{let r=e.sourceCode.getCommentsBefore(s).at(-1);if(r===void 0||!f(r))return;let a=Ee(e.sourceCode,r);if(a===null||!qe(n,e.sourceCode.visitorKeys))return;let m=e.sourceCode.getIndexFromLoc({line:a.from,column:0}),d=e.sourceCode.getIndexFromLoc({line:a.to+1,column:0});e.report({loc:{start:{line:a.from,column:0},end:{line:a.to,column:(e.sourceCode.lines[a.to-1]??"").length}},messageId:"voidReturns",fix:g=>g.removeRange([m,d])});};return {FunctionDeclaration(n){i(n,x(n));},VariableDeclarator(n){(n.init?.type==="ArrowFunctionExpression"||n.init?.type==="FunctionExpression")&&i(n.init,x(n.init));},MethodDefinition(n){n.value.type==="FunctionExpression"&&i(n.value,n);}}}},Ve=new $;function N(t){return o.COMMENTS.DIRECTIVE.test(t.value)}function Ge(t){let e=t.range[0]+2;if(t.type==="Line"){let n=t.value.match(/\S/u);return n?.index===void 0?null:{index:e+n.index,char:n[0]}}let i=0;for(let n of t.value.split(`
|
|
6
|
+
`)){let s=(n.match(/^\s*\*?\s*/u)?.[0]??"").length,r=n.slice(s).charAt(0);if(r!=="")return {index:e+i+s,char:r};i+=n.length+1;}return null}function Ke(t){let e=[],i=t.range[0]+2,n=null;for(let s=0;s<t.value.length;s++){let r=t.value.charAt(s);if(n!==null){r===n&&(n=null);continue}if(o.COMMENTS.QUOTES.has(r)&&t.value.includes(r,s+1)){n=r;continue}if(r!==".")continue;if(t.value.charAt(s+1)==="."){for(;t.value.charAt(s+1)===".";)s++;continue}let a=t.value.slice(s+1);a!==""&&!/^\s/u.test(a)||vt(t.value.slice(0,s+1))||e.push({index:i+s,terminal:a.trim()===""});}return e}function $e(t){let e=[],i=t.range[0]+2;for(let n=0;n<t.value.length;n++){if(t.value.charAt(n)!=="`")continue;if(t.value.charAt(n+1)==="`"){for(;t.value.charAt(n+1)==="`";)n++;continue}let s=t.value.indexOf("`",n+1);if(s===-1)break;let r=t.value.slice(n+1,s);r.includes('"')||e.push({start:i+n,end:i+s,text:r}),n=s;}return e}function vt(t){let e=t.toLowerCase();return o.COMMENTS.ABBREVIATIONS.some(i=>{if(!e.endsWith(i))return false;let n=e.charAt(e.length-i.length-1);return n===""||!ve(n)})}var H=class extends l{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:p({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(e){return {Program(){for(let i of e.sourceCode.getAllComments())if(!(i.type!=="Line"||N(i)))for(let n of $e(i))e.report({loc:{start:e.sourceCode.getLocFromIndex(n.start),end:e.sourceCode.getLocFromIndex(n.end+1)},messageId:"backticks",data:{text:n.text},fix:s=>[s.replaceTextRange([n.start,n.start+1],'"'),s.replaceTextRange([n.end,n.end+1],'"')]});}}}},He=new H;var X=class extends l{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:p({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:p({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(e){return {Program(){for(let i of e.sourceCode.getAllComments())if(i.type==="Line")for(let n of Ke(i)){let s={start:e.sourceCode.getLocFromIndex(n.index),end:e.sourceCode.getLocFromIndex(n.index+1)};if(n.terminal){e.report({loc:s,messageId:"period",fix:r=>r.removeRange([n.index,n.index+1])});continue}e.report({loc:s,messageId:"sentence"});}}}}},Xe=new X;var Y=class extends l{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:p({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(e){let i=[],n=new Set,s=r=>{if(r.type!=="MemberExpression")return;let a=I(r);a!==null&&n.add(a);};return {AssignmentExpression(r){s(r.left);},UpdateExpression(r){s(r.argument);},VariableDeclarator(r){if(r.parent.type!=="VariableDeclaration"||r.parent.kind!=="const"||r.parent.parent.type==="ExportNamedDeclaration"||r.id.type!=="Identifier"||r.init===null||r.id.typeAnnotation!==void 0)return;let a=I(r.init);if(a===null)return;let m=a.slice(0,a.indexOf("."));m!=="this"&&C(e.sourceCode.getScope(r),m)||i.push({node:r,name:r.id.name,path:a,expression:e.sourceCode.getText(r.init)});},"Program:exit"(){for(let r of i)Ne(n,r.path)||e.report({node:r.node,messageId:"propertyAccessAlias",data:{name:r.name,expression:r.expression}});}}}},Ye=new Y;var Z=class extends l{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:p({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(e){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"&&!ke(i.init)||De(i.id)&&e.report({node:i,messageId:"destructure",data:{source:e.sourceCode.getText(i.init)}}));}}}},Ze=new Z;var Q=class extends l{name="no-relative-imports";defaultOptions=[{allowIn:[]}];meta={type:"suggestion",docs:{description:"Disallow relative import and re-export specifiers, use the package path alias.",recommended:true,category:"base"},schema:[{type:"object",properties:{allowIn:{type:"array",items:{type:"string"}}},additionalProperties:false}],messages:{relative:p({problem:"This import uses a relative path (`{{path}}`).",why:"A relative path breaks when a file moves and hides which package a module belongs to, the path alias is stable and explicit",fix:"Import through the package alias (`#...` or `@frontend/...`) instead of a relative path"})}};create(e,i){let n=i[0]?.allowIn??[];if(n.length>0&&h(e.filename,n))return {};let s=r=>{r!=null&&(!r.value.startsWith("./")&&!r.value.startsWith("../")||e.report({node:r,messageId:"relative",data:{path:r.value}}));};return {ImportDeclaration(r){s(r.source);},ExportNamedDeclaration(r){s(r.source);},ExportAllDeclaration(r){s(r.source);},ImportExpression(r){r.source.type==="Literal"&&typeof r.source.value=="string"&&s(r.source);}}}},Qe=new Q;var ee=class extends l{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:p({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(e){return {Program(){for(let i of e.sourceCode.getAllComments()){if(!f(i)||i.loc.start.line!==i.loc.end.line)continue;let n=i.value.replace(/^\*/,"").trim();n.length!==0&&e.report({loc:i.loc,messageId:"singleLine",fix(s){let r=" ".repeat(i.loc.start.column),a=`/**
|
|
7
|
+
${r} * ${n}
|
|
8
|
+
${r} */`;return s.replaceTextRange(i.range,a)}});}}}}},et=new ee;var te=class extends l{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:p({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(e){let i=n=>{if(n.type!=="Line")return false;let s=e.sourceCode.lines[n.loc.start.line-2];return s!==void 0&&/^\s*\/\//.test(s)};return {Program(){for(let n of e.sourceCode.getAllComments()){if(N(n)||i(n))continue;let s=Ge(n);s===null||!new RegExp("\\p{Ll}","u").test(s.char)||/^(?:https?:\/\/|www\.)/u.test(e.sourceCode.getText().slice(s.index))||e.report({loc:{start:e.sourceCode.getLocFromIndex(s.index),end:e.sourceCode.getLocFromIndex(s.index+s.char.length)},messageId:"capitalize",fix:r=>r.replaceTextRange([s.index,s.index+s.char.length],s.char.toUpperCase())});}}}}},tt=new te;var it={adonisjs:"AdonisJS",react:"React"};function zt(t){let e=[];for(let i of t.ast.body)i.type==="ImportDeclaration"&&e.push(String(i.source.value));return e}function rt(t,e){let i=new Set,n=zt(t);return n.some(r=>r.startsWith("@adonisjs/")||o.FRAMEWORKS.ADONIS_SUBPATH.test(r))&&i.add("adonisjs"),(n.some(r=>r==="react"||r.startsWith("react/")||r==="react-dom")||o.FRAMEWORKS.REACT_FILE.test(e))&&i.add("react"),i}var ie=class extends l{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:p({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(e,i){let n=new Set(i[0]?.ignore??[]),s=e.settings[o.PLUGIN_NAME]??{};return {Program(r){let a=rt(e.sourceCode,e.filename);for(let m of a)n.has(m)||s[m]||e.report({node:r,messageId:"missingConfig",data:{framework:it[m],config:m}});}}}},nt=new ie;function re(t){return /^[A-Z]/.test(t)}function D(t){return o.REACT.HOOK.test(t)}function st(t){return o.REACT.CONTEXT_HOOK.test(t)}function ne(t){return t?t.type==="ArrowFunctionExpression"||t.type==="FunctionExpression"?true:t.type==="CallExpression"&&t.callee.type==="Identifier"&&t.callee.name==="useCallback":false}function S(t){if(!t)return false;switch(t.type){case "JSXElement":case "JSXFragment":return true;case "ConditionalExpression":return S(t.consequent)||S(t.alternate);case "LogicalExpression":return S(t.left)||S(t.right);case "SequenceExpression":return S(t.expressions.at(-1));default:return false}}function se(t,e){return t.type==="ArrowFunctionExpression"&&t.body.type!=="BlockStatement"?S(t.body):b(t.body,e,S)}function ot(t,e){let i=T(t);return i===void 0?false:D(i)||re(i)&&se(t,e)}function at(t,e){if(t.type==="CallExpression")return !(t.callee.type==="Identifier"&&D(t.callee.name));for(let i of e[t.type]??[]){let n=t[i],s=Array.isArray(n)?n:[n];for(let r of s){let a=r;if(!(!a||typeof a.type!="string")&&!o.FUNCTIONS.NODE_TYPES.has(a.type)&&at(a,e))return true}}return false}function lt(t,e){return t.type==="ArrowFunctionExpression"||t.type==="FunctionExpression"?false:at(t,e)}var oe=class extends l{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:p({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(e){let i=(n,s)=>{let r=T(n);if(r===void 0)return;let a=x(n);Ue(a)&&(We(n)||re(r)&&se(n,e.sourceCode.visitorKeys)||y(e.sourceCode,a)||e.report({node:s,messageId:"missingJSDoc",data:{name:r}}));};return {FunctionDeclaration(n){i(n,n.id??n);},VariableDeclarator(n){n.init&&(n.init.type!=="ArrowFunctionExpression"&&n.init.type!=="FunctionExpression"||i(n.init,n.id));}}}},pt=new oe;function ct(t,e,i){let s=(t.lines[e.loc.start.line-1]??"").match(/^\s*/)?.[0]??"",r=s+" ".repeat(i);return `{
|
|
9
|
+
${e.properties.map(m=>`${r}${t.getText(m)}`).join(`,
|
|
10
10
|
`)},
|
|
11
|
-
${
|
|
12
|
-
`)??[]).filter(m=>
|
|
11
|
+
${s}}`}var ae=class extends l{name="require-multiline-object";defaultOptions=[{maxKeys:o.OBJECTS.MAX_INLINE_KEYS,indent:o.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:p({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(e,i){let n=i[0]?.maxKeys??o.OBJECTS.MAX_INLINE_KEYS,s=i[0]?.indent??o.OBJECTS.INDENT_WIDTH;return {ObjectExpression(r){if(r.properties.length<=n||r.loc.start.line!==r.loc.end.line)return;let a=e.sourceCode.getCommentsInside(r).length>0;e.report({node:r,messageId:"shouldWrap",data:{count:r.properties.length,max:n},fix:a?null:m=>m.replaceText(r,ct(e.sourceCode,r,s))});}}}},ut=new ae;var le=class extends l{name="no-jsx-comments";defaultOptions=[];meta={type:"suggestion",docs:{description:"Disallow inline `{/* ... */}` comments inside JSX.",recommended:true,category:"react"},schema:[],messages:{jsxComment:p({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(e){return {JSXExpressionContainer(i){i.expression.type==="JSXEmptyExpression"&&e.sourceCode.getCommentsInside(i).length!==0&&e.report({node:i,messageId:"jsxComment"});}}}},mt=new le;var pe=class extends l{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:p({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(e){return {VariableDeclarator(i){i.id.type!=="Identifier"||i.init?.type!=="CallExpression"||i.init.callee.type!=="Identifier"||!st(i.init.callee.name)||e.report({node:i,messageId:"destructure",data:{hook:i.init.callee.name,name:i.id.name}});}}}},dt=new pe;var ce=class extends l{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:p({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(e){return {VariableDeclarator(i){if(i.parent.type!=="VariableDeclaration"||i.parent.kind!=="const"||i.id.type!=="Identifier"||i.init===null)return;let n=Be(i);n===null||!ot(n,e.sourceCode.visitorKeys)||lt(i.init,e.sourceCode.visitorKeys)&&e.report({node:i,messageId:"useMemo"});}}}},ft=new ce;var ue=class extends l{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:p({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(e){let i=r=>{if(ne(r))return true;if(r.type!=="Identifier")return false;let m=ASTUtils.findVariable(e.sourceCode.getScope(r),r.name)?.defs.at(-1)?.node;return m?.type==="VariableDeclarator"&&ne(m.init)},n=r=>{e.report({node:r,messageId:"wrapInObject",fix:r.type==="Identifier"?a=>a.replaceText(r,`{ ${r.name} }`):void 0});},s=r=>{let a=T(r);if(!(a===void 0||!D(a))){if(r.type==="ArrowFunctionExpression"&&r.body.type!=="BlockStatement"){i(r.body)&&n(r.body);return}b(r.body,e.sourceCode.visitorKeys,m=>(m!==null&&i(m)&&n(m),false));}};return {FunctionDeclaration(r){s(r);},FunctionExpression(r){s(r);},ArrowFunctionExpression(r){s(r);}}}},gt=new ue;var me=class extends l{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:p({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:p({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(e){return {VariableDeclarator(i){if(i.init?.type!=="CallExpression"||i.init.callee.type!=="Identifier"||!o.REACT.MEMO_HOOKS.has(i.init.callee.name))return;let n=i.parent;if(n.parent?.type==="ExportNamedDeclaration"&&(n=n.parent),!y(e.sourceCode,n)){e.report({node:i.id,messageId:"missingJSDoc",data:{hook:i.init.callee.name}});return}if(i.init.callee.name!=="useCallback")return;let s=i.init.arguments[0];if(s?.type!=="ArrowFunctionExpression"&&s?.type!=="FunctionExpression"||s.params.length===0)return;(e.sourceCode.getCommentsBefore(n).at(-1)?.value.split(`
|
|
12
|
+
`)??[]).filter(m=>O(m)==="param").length<s.params.length&&e.report({node:i.id,messageId:"missingParam"});}}}},yt=new me;var jt=[he,xe,Re,Oe,Ie,Le,we,ze,je,Pe,_e,Je,Ve,He,Xe,Ye,Ze,Qe,et,tt,nt,pt,ut,mt,dt,ft,gt,yt],R=Object.fromEntries(jt.map(t=>[t.name,t.toRuleModule()]));function E(t){let e={};for(let[i,n]of Object.entries(R))(n.meta.docs?.category??"base")===t&&(e[`${o.PLUGIN_NAME}/${i}`]="warn");return e}function St(){let t={};for(let e of Object.keys(R))t[`${o.PLUGIN_NAME}/${e}`]="warn";return t}function ht(t){return {name:`${o.PLUGIN_NAME}/all`,plugins:{[o.PLUGIN_NAME]:t},settings:{[o.PLUGIN_NAME]:{adonisjs:true,react:true}},rules:St()}}function w(t){return {name:`${o.PLUGIN_NAME}/base`,plugins:{[o.PLUGIN_NAME]:t},rules:E("base")}}function Tt(t){return {...w(t),name:`${o.PLUGIN_NAME}/recommended`}}var Pt=["**/start/routes.ts","**/start/routes/**/*.ts"];function bt(t){return {name:`${o.PLUGIN_NAME}/adonisjs`,plugins:{[o.PLUGIN_NAME]:t},settings:{[o.PLUGIN_NAME]:{adonisjs:true}},rules:{...E("adonisjs"),[`${o.PLUGIN_NAME}/no-decorative-comment-separators`]:["warn",{allowIn:Pt}]}}}function Et(t){return {name:`${o.PLUGIN_NAME}/react`,plugins:{[o.PLUGIN_NAME]:t},settings:{[o.PLUGIN_NAME]:{react:true}},rules:E("react")}}function xt(t){return {base:w(t),recommended:Tt(t),adonisjs:bt(t),react:Et(t),all:ht(t)}}var Rt="0.7.0";var de={meta:{name:`eslint-plugin-${o.PLUGIN_NAME}`,version:Rt},rules:R,configs:{}};de.configs=xt(de);var Go=de;export{Go as default};//# sourceMappingURL=index.js.map
|
|
13
13
|
//# sourceMappingURL=index.js.map
|