@alien_intelligence/eslint-plugin-nitpicker 0.4.0 → 0.5.1
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 +32 -2
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/package.json +75 -75
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<br />
|
|
3
3
|
<a href="https://www.alien.club" target="_blank"><img width="64px" src="https://alien-website.cdn.prismic.io/alien-website/Zrn2b0aF0TcGI3Bu_alien-logo.svg" /></a>
|
|
4
|
-
<h2 align="center">@
|
|
4
|
+
<h2 align="center">@Alien-Intelligence/eslint-plugin-nitpicker</h2>
|
|
5
5
|
<p align="center">A hyper-pedantic ESLint plugin that flags every stylistic<br />and semantic nit, specifically for AI.</p>
|
|
6
6
|
</p>
|
|
7
7
|
|
|
@@ -78,7 +78,8 @@ Every rule is part of `recommended` and enabled as a warning. The Fixable column
|
|
|
78
78
|
| `nitpicker/no-decorative-comment-separators` | | Disallow decorative separators (banners, box-drawing, repeated dashes) inside comments. |
|
|
79
79
|
| `nitpicker/no-em-dash` | | Disallow the em dash character anywhere in the source. |
|
|
80
80
|
| `nitpicker/no-jsdoc-blank-before-tags` | yes | Disallow blank lines before JSDoc tags such as `@param` or `@returns`. |
|
|
81
|
-
| `nitpicker/no-line-comment-
|
|
81
|
+
| `nitpicker/no-line-comment-backticks` | yes | Disallow backticks in `//` line comments, rewriting code references with double quotes. |
|
|
82
|
+
| `nitpicker/no-line-comment-period` | yes | Disallow prose periods in `//` line comments (code dots, quoted spans, ellipses, `e.g.` are OK). |
|
|
82
83
|
| `nitpicker/no-property-access-alias` | | Disallow a `const` whose whole value is a single property access; inline the expression instead. |
|
|
83
84
|
| `nitpicker/no-single-line-jsdoc` | yes | Require JSDoc comments to span multiple lines rather than a single line. |
|
|
84
85
|
| `nitpicker/require-framework-config` | | Warn when a file uses a framework whose Nitpicker config is not enabled. |
|
|
@@ -112,6 +113,35 @@ A few rules accept options. Pass them by overriding the rule with a `["warn", {
|
|
|
112
113
|
"nitpicker/require-framework-config": ["warn", { ignore: ["react"] }],
|
|
113
114
|
```
|
|
114
115
|
|
|
116
|
+
`no-em-dash` takes `{ allow: ("strings" | "templates" | "jsx" | "comments")[] }`, the places an em dash is deliberate rather than AI residue, such as user-facing copy, prompt text, or a glyph standing in for an empty value. It defaults to `[]`, i.e. an em dash is reported anywhere. Scope it to the files that hold copy rather than enabling it globally:
|
|
117
|
+
```js
|
|
118
|
+
{
|
|
119
|
+
files: ["app/legal/**/*.tsx", "app/prompts/**/*.ts"],
|
|
120
|
+
rules: {
|
|
121
|
+
"nitpicker/no-em-dash": ["warn", { allow: ["strings", "templates", "jsx"] }],
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Line comment code references
|
|
127
|
+
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
|
+
```js
|
|
129
|
+
// Reads `auth.user` from the context -> // Reads "auth.user" from the context
|
|
130
|
+
```
|
|
131
|
+
Backticks are left alone in JSDoc and block comments, in tooling directives, when unpaired, in a run (a ```` ``` ```` fence), and when the span already holds a double quote, since `` `split(".")` `` cannot be requoted without nesting.
|
|
132
|
+
|
|
133
|
+
### Line comment periods
|
|
134
|
+
`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
|
+
|
|
136
|
+
The two prose cases are fixed differently, since removing a period is only safe at the end of a comment:
|
|
137
|
+
```js
|
|
138
|
+
// Reads the token. -> // Reads the token
|
|
139
|
+
// Reads the token. It is cached -> // Reads the token
|
|
140
|
+
// // It is cached
|
|
141
|
+
const a = 1 // Reads the token. Cached -> reported, not fixed
|
|
142
|
+
```
|
|
143
|
+
A mid-comment period is split onto its own line rather than deleted, which would leave a run-on. A trailing comment is reported without a fix, as splitting it would break the line it sits on.
|
|
144
|
+
|
|
115
145
|
## Framework configs
|
|
116
146
|
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.
|
|
117
147
|
|
package/dist/index.js
CHANGED
|
@@ -1,12 +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;
|
|
5
|
-
`);for(let
|
|
1
|
+
import {ESLintUtils,ASTUtils}from'@typescript-eslint/utils';var st={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"]}},a=st;var ie=ESLintUtils.RuleCreator(e=>`${a.REPO_URL}/blob/main/docs/rules/${e}.md`);var u=class{toRuleModule(){return ie({name:this.name,meta:this.meta,defaultOptions:this.defaultOptions,create:(t,i)=>this.create(t,i)})}};function m({problem:e,why:t,fix:i}){return `${e}
|
|
2
|
+
- why: ${t}
|
|
3
|
+
- fix: ${i}`}function re(e){return e.parent.type==="ExportDefaultDeclaration"&&e.superClass?.type==="Identifier"&&e.superClass.name==="BaseSchema"}function ne(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 oe(e,t){if(e.type!=="ExpressionStatement")return null;let i=lt(e.expression,t);return i===null?null:a.MIGRATIONS.INDEX_METHODS.has(i.method)?"index":i.method==="timestamps"?"timestamp":a.MIGRATIONS.TIMESTAMP_METHODS.has(i.method)?i.firstArgument!==void 0&&a.MIGRATIONS.AUDIT_TIMESTAMPS.has(i.firstArgument)?"timestamp":null:"column"}function lt(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 N=class extends u{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:m({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=ne(i);if(r===null)return;let o=0;for(let n of r.body){let s=oe(n,r.builderName);if(s===null)continue;let l=a.MIGRATIONS.CATEGORY_ORDER.indexOf(s);l<o&&t.report({node:n,messageId:"outOfOrder",data:{category:s}}),o=Math.max(o,l);}}}}},se=new N;function ae(e){return e.parent.type==="ExportDefaultDeclaration"&&e.id?.name.endsWith("Controller")===true}function g(e){return e.type==="Block"&&e.value.startsWith("*")}function ct(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(ct(t)).at(-1);return r!==void 0&&g(r)}function D(e){return /^\s*\*\s*$/.test(e)}function le(e){return e.match(a.JSDOC.TAG)?.[1]??null}function k(e){return le(e)!==null}function ce(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 pe(e,t){let i=-1;for(let o=t.loc.start.line+1;o<t.loc.end.line;o++){let n=le(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(k(e.lines[o-1]??"")){r=o-1;break}return {from:i,to:r}}var w=class extends u{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:m({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){ae(i)&&(S(t.sourceCode,i.parent)||t.report({node:i.id??i,messageId:"missingJSDoc"}));}}}},ue=new w;var A=class extends u{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:m({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){re(i)&&(S(t.sourceCode,i.parent)||t.report({node:i.id??i,messageId:"missingJSDoc"}));}}}},me=new A;var de=250,M=class extends u{name="max-jsdoc-description-length";defaultOptions=[{max:de}];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:m({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??de;return {Program(){for(let o of t.sourceCode.getAllComments()){if(!g(o))continue;let n=ce(o).length;n<=r||t.report({loc:o.loc,messageId:"tooLong",data:{length:n,max:r}});}}}}},fe=new M;function R(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 ge(e){return R(e)!==null}function O(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 ye(e,t){for(let i of e)if(t===i||t.startsWith(`${i}.`))return true;return false}function Se(e){return e.properties.length===0?false:e.properties.every(t=>t.type==="Property"&&t.shorthand&&!t.computed&&t.value.type==="Identifier")}var v=class extends u{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:m({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&&(O(t.sourceCode.getScope(i),i.init.name)||t.report({node:i,messageId:"alias",data:{name:i.id.name,source:i.init.name}})));}}}},he=new v;var Te={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 be(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 F(e){let t=[];for(let i of e.matchAll(a.WORDS.SUB_WORD))i.index!==void 0&&t.push({text:i[0],index:i.index});return t}function j(e,t){return e===e.toUpperCase()?t.toUpperCase():e.charAt(0)===e.charAt(0).toUpperCase()?t.charAt(0).toUpperCase()+t.slice(1):t}function Ee(e){return e!==void 0&&a.WORDS.WORD_CHAR.test(e)}var P=class extends u{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:m({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=be(Te,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 F(o.name)){let s=r[n.text.toLowerCase()];s!==void 0&&t.report({node:o,messageId:"british",data:{british:n.text,american:j(n.text,s)}});}},Program(){for(let o of t.sourceCode.getAllComments())for(let n of F(o.value)){let s=r[n.text.toLowerCase()];if(s===void 0)continue;let l=j(n.text,s),d=o.range[0]+2+n.index,f=d+n.text.length;t.report({loc:{start:t.sourceCode.getLocFromIndex(d),end:t.sourceCode.getLocFromIndex(f)},messageId:"british",data:{british:n.text,american:l},fix:b=>b.replaceTextRange([d,f],l)});}}}}},xe=new P;function Re(e){let t=e.replace(/^\s*\*?\s*/,"").trimEnd();return t.length===0?false:a.COMMENTS.BOX_DRAWING.test(t)||a.COMMENTS.PURE_SEPARATOR.test(t)||a.COMMENTS.WRAPPED_LABEL.test(t)}function ut(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 Oe(e,t){let i=e.replace(/\\/g,"/");return t.some(r=>ut(r).test(i))}var _=class extends u{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:m({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&&Oe(t.filename,r)?{}:{Program(){for(let o of t.sourceCode.getAllComments()){let n=o.value.split(`
|
|
5
|
+
`);for(let s=0;s<n.length;s++){let l=n[s];if(l===void 0||!Re(l))continue;let d=o.loc.start.line+s,f=t.sourceCode.lines[d-1]??"";t.report({loc:{start:{line:d,column:0},end:{line:d,column:f.length}},messageId:"decorative"});}}}}}},Ce=new _;var mt={strings:"String",templates:"Template",jsx:"JSXText"},J=class extends u{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:m({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){let r=new Set(i[0]?.allow??[]),o=()=>{let n=[];if(r.size===0)return n;let s=new Set([...r].map(l=>mt[l]).filter(l=>l!==void 0));for(let l of t.sourceCode.ast.tokens??[])s.has(l.type)&&n.push(l.range);if(r.has("comments"))for(let l of t.sourceCode.getAllComments())n.push(l.range);return n};return {Program(){let n=t.sourceCode.getText(),s=o();for(let l=0;l<n.length;l++)n[l]===a.EM_DASH&&(s.some(([d,f])=>l>=d&&l<f)||t.report({loc:{start:t.sourceCode.getLocFromIndex(l),end:t.sourceCode.getLocFromIndex(l+1)},messageId:"emDash"}));}}}},Le=new J;var z=class extends u{name="no-emojis";defaultOptions=[];meta={type:"suggestion",fixable:"code",docs:{description:"Disallow emoji characters anywhere in the source.",recommended:true,category:"base"},schema:[],messages:{emoji:m({problem:"Found an emoji ({{emoji}}).",why:"Emojis are usually introduced by AI-generated text and add noise to code, comments, and identifiers",fix:"Discard the emoji"})}};create(t){let i=t.sourceCode.getText();return {Program(){for(let r of i.matchAll(a.EMOJI)){let o=r[0],n=r.index+o.length;t.report({loc:{start:t.sourceCode.getLocFromIndex(r.index),end:t.sourceCode.getLocFromIndex(n)},messageId:"emoji",data:{emoji:o},fix:s=>s.removeRange([r.index,n])});}}}}},Ie=new z;var B=class extends u{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:m({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(g(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||!D(o))continue;let n=r;for(;n<i.loc.end.line&&D(t.sourceCode.lines[n]??"");)n++;let s=t.sourceCode.lines[n];if(s!==void 0&&k(s)){let l=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:f=>f.removeRange([l,d])});}r=n;}}}}},Ne=new B;function E(e){let t=e;return t.parent.type==="VariableDeclarator"&&t.parent.parent.type==="VariableDeclaration"&&(t=t.parent.parent),(t.parent.type==="ExportNamedDeclaration"||t.parent.type==="ExportDefaultDeclaration")&&(t=t.parent),t}function De(e){return e.parent?.type==="Program"}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 s of n){let l=s;if(!(!l||typeof l.type!="string")&&!a.FUNCTIONS.NODE_TYPES.has(l.type)&&h(l,t,i))return true}}return false}function dt(e,t){return e.type==="ArrowFunctionExpression"&&e.body.type!=="BlockStatement"?true:h(e.body,t,i=>i!==null)}function ft(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 ke(e,t){return e.returnType?ft(e.returnType):!dt(e,t)}var U=class extends u{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:m({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||!g(n))return;let s=pe(t.sourceCode,n);if(s===null||!ke(r,t.sourceCode.visitorKeys))return;let l=t.sourceCode.getIndexFromLoc({line:s.from,column:0}),d=t.sourceCode.getIndexFromLoc({line:s.to+1,column:0});t.report({loc:{start:{line:s.from,column:0},end:{line:s.to,column:(t.sourceCode.lines[s.to-1]??"").length}},messageId:"voidReturns",fix:f=>f.removeRange([l,d])});};return {FunctionDeclaration(r){i(r,E(r));},VariableDeclarator(r){(r.init?.type==="ArrowFunctionExpression"||r.init?.type==="FunctionExpression")&&i(r.init,E(r.init));},MethodDefinition(r){r.value.type==="FunctionExpression"&&i(r.value,r);}}}},we=new U;function L(e){return a.COMMENTS.DIRECTIVE.test(e.value)}function Ae(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 Me(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(a.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 s=e.value.slice(o+1);s!==""&&!/^\s/u.test(s)||gt(e.value.slice(0,o+1))||t.push({index:i+o,terminal:s.trim()===""});}return t}function ve(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 gt(e){let t=e.toLowerCase();return a.COMMENTS.ABBREVIATIONS.some(i=>{if(!t.endsWith(i))return false;let r=t.charAt(t.length-i.length-1);return r===""||!Ee(r)})}var W=class extends u{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:m({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"||L(i)))for(let r of ve(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],'"')]});}}}},Fe=new W;var $=class extends u{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:m({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:m({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"})}};create(t){let i=r=>{let o=(t.sourceCode.lines[r.loc.start.line-1]??"").slice(0,r.loc.start.column);return o.trim()===""?o:null};return {Program(){for(let r of t.sourceCode.getAllComments()){if(r.type!=="Line")continue;let o=i(r);for(let n of Me(r)){let s={start:t.sourceCode.getLocFromIndex(n.index),end:t.sourceCode.getLocFromIndex(n.index+1)};if(n.terminal){t.report({loc:s,messageId:"period",fix:b=>b.removeRange([n.index,n.index+1])});continue}let l=n.index-r.range[0]-2,d=r.value.slice(l+1).match(/^\s*/u)?.[0]??"",f=n.index+1+d.length;t.report({loc:s,messageId:"sentence",fix:o===null?null:b=>b.replaceTextRange([n.index,f],`
|
|
7
|
+
${o}// `)});}}}}}},je=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}});}}}},Pe=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)}}));}}}},_e=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=`/**
|
|
6
8
|
${n} * ${r}
|
|
7
|
-
${n} */`;return o.replaceTextRange(i.range,
|
|
8
|
-
|
|
9
|
-
${e.properties.map(m=>`${n}${t.getText(m)}`).join(`,
|
|
9
|
+
${n} */`;return o.replaceTextRange(i.range,s)}});}}}}},Je=new K;var q=class extends u{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:m({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(L(r)||i(r))continue;let o=Ae(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())});}}}}},ze=new q;var Be={adonisjs:"AdonisJS",react:"React"};function yt(e){let t=[];for(let i of e.ast.body)i.type==="ImportDeclaration"&&t.push(String(i.source.value));return t}function Ue(e,t){let i=new Set,r=yt(e);return r.some(n=>n.startsWith("@adonisjs/")||a.FRAMEWORKS.ADONIS_SUBPATH.test(n))&&i.add("adonisjs"),(r.some(n=>n==="react"||n.startsWith("react/")||n==="react-dom")||a.FRAMEWORKS.REACT_FILE.test(t))&&i.add("react"),i}var H=class extends u{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:m({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[a.PLUGIN_NAME]??{};return {Program(n){let s=Ue(t.sourceCode,t.filename);for(let l of s)r.has(l)||o[l]||t.report({node:n,messageId:"missingConfig",data:{framework:Be[l],config:l}});}}}},We=new H;function $e(e){return /^[A-Z]/.test(e)}function Ve(e){return a.REACT.HOOK.test(e)}function Ge(e){return a.REACT.CONTEXT_HOOK.test(e)}function X(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 Ke(e,t){return e.type==="ArrowFunctionExpression"&&e.body.type!=="BlockStatement"?y(e.body):h(e.body,t,y)}var Y=class extends u{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:m({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 s=E(r);De(s)&&($e(n)&&Ke(r,t.sourceCode.visitorKeys)||S(t.sourceCode,s)||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));}}}},qe=new Y;function He(e,t,i){let o=(e.lines[t.loc.start.line-1]??"").match(/^\s*/)?.[0]??"",n=o+" ".repeat(i);return `{
|
|
10
|
+
${t.properties.map(l=>`${n}${e.getText(l)}`).join(`,
|
|
10
11
|
`)},
|
|
11
|
-
${o}}`}var
|
|
12
|
+
${o}}`}var Z=class extends u{name="require-multiline-object";defaultOptions=[{maxKeys:a.OBJECTS.MAX_INLINE_KEYS,indent:a.OBJECTS.INDENT_WIDTH}];meta={type:"suggestion",fixable:"whitespace",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:m({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??a.OBJECTS.MAX_INLINE_KEYS,o=i[0]?.indent??a.OBJECTS.INDENT_WIDTH;return {ObjectExpression(n){n.properties.length<=r||n.loc.start.line===n.loc.end.line&&t.report({node:n,messageId:"shouldWrap",data:{count:n.properties.length,max:r},fix:s=>s.replaceText(n,He(t.sourceCode,n,o))});}}}},Xe=new Z;var Q=class extends u{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:m({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"||!Ge(i.init.callee.name)||t.report({node:i,messageId:"destructure",data:{hook:i.init.callee.name,name:i.id.name}});}}}},Ye=new Q;var ee=class extends u{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:m({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(X(n))return true;if(n.type!=="Identifier")return false;let l=ASTUtils.findVariable(t.sourceCode.getScope(n),n.name)?.defs.at(-1)?.node;return l?.type==="VariableDeclarator"&&X(l.init)},r=n=>{t.report({node:n,messageId:"wrapInObject",fix:n.type==="Identifier"?s=>s.replaceText(n,`{ ${n.name} }`):void 0});},o=n=>{let s=C(n);if(!(s===void 0||!Ve(s))){if(n.type==="ArrowFunctionExpression"&&n.body.type!=="BlockStatement"){i(n.body)&&r(n.body);return}h(n.body,t.sourceCode.visitorKeys,l=>(l!==null&&i(l)&&r(l),false));}};return {FunctionDeclaration(n){o(n);},FunctionExpression(n){o(n);},ArrowFunctionExpression(n){o(n);}}}},Ze=new ee;var ht=[se,ue,me,fe,he,xe,Ce,Le,Ie,Ne,we,Fe,je,Pe,_e,Je,ze,We,qe,Xe,Ye,Ze],x=Object.fromEntries(ht.map(e=>[e.name,e.toRuleModule()]));function T(e){let t={};for(let[i,r]of Object.entries(x))(r.meta.docs?.category??"base")===e&&(t[`${a.PLUGIN_NAME}/${i}`]="warn");return t}function Qe(){let e={};for(let t of Object.keys(x))e[`${a.PLUGIN_NAME}/${t}`]="warn";return e}function et(e){return {name:`${a.PLUGIN_NAME}/all`,plugins:{[a.PLUGIN_NAME]:e},settings:{[a.PLUGIN_NAME]:{adonisjs:true,react:true}},rules:Qe()}}function I(e){return {name:`${a.PLUGIN_NAME}/base`,plugins:{[a.PLUGIN_NAME]:e},rules:T("base")}}function tt(e){return {...I(e),name:`${a.PLUGIN_NAME}/recommended`}}var Tt=["**/start/routes.ts","**/start/routes/**/*.ts"];function it(e){return {name:`${a.PLUGIN_NAME}/adonisjs`,plugins:{[a.PLUGIN_NAME]:e},settings:{[a.PLUGIN_NAME]:{adonisjs:true}},rules:{...T("adonisjs"),[`${a.PLUGIN_NAME}/no-decorative-comment-separators`]:["warn",{allowIn:Tt}]}}}function rt(e){return {name:`${a.PLUGIN_NAME}/react`,plugins:{[a.PLUGIN_NAME]:e},settings:{[a.PLUGIN_NAME]:{react:true}},rules:T("react")}}function nt(e){return {base:I(e),recommended:tt(e),adonisjs:it(e),react:rt(e),all:et(e)}}var ot="0.5.1";var te={meta:{name:`eslint-plugin-${a.PLUGIN_NAME}`,version:ot},rules:x,configs:{}};te.configs=nt(te);var zo=te;export{zo as default};//# sourceMappingURL=index.js.map
|
|
12
13
|
//# sourceMappingURL=index.js.map
|