@kitschpatrol/eslint-config 8.1.0 → 8.3.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/bin/cli.js +6 -7
- package/dist/index.d.ts +443 -338
- package/dist/index.js +1 -1
- package/init/.vscode/tasks.json +73 -0
- package/package.json +16 -16
- package/readme.md +32 -8
package/bin/cli.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cosmiconfig as e}from"cosmiconfig";import{TypeScriptLoader as t}from"cosmiconfig-typescript-loader";import{execa as n}from"execa";import r from"fs-extra";import i from"node:fs";import a from"node:path";import{PassThrough as
|
|
3
|
-
`)
|
|
4
|
-
`)}})}function
|
|
5
|
-
`);
|
|
6
|
-
`),
|
|
7
|
-
`),0;let o=
|
|
8
|
-
`);for(let e of o)t.write(`${e}\n`);return 0},name:`Cosmiconfig ${e}`}}async function q(n){let r=e(n,{loaders:{".ts":t()},searchStrategy:`project`});try{let e=await r.search();if(e===null){console.error(`No ${n} configuration found.`);return}return e}catch(e){console.error(`Error while searching for ${n} configuration:`,e);return}}const J={fileRun:`Matches files below the current working directory by default.`,monorepoRun:`In a monorepo, it will also run in all packages below the current working directory.`,monorepoSearch:`Searches up to the root of a monorepo if necessary.`,multiArgumentCaveat:`Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package scope.`,multiOptionCaveat:`Will use option flags where possible if provided, but some of the invoked tools will ignore them.`,optionalFileRun:`Package-scoped by default, file-scoped if a file argument is provided.`,packageRun:`Package-scoped.`,packageSearch:`Package-scoped.`};async function Y(e,t){let n,[r]=t;if(r===void 0)n=K(`eslint`);else{let t=a.join(process.cwd(),r);e.write(`Showing configuration for file: ${t}\n`),n={name:`eslint`,optionFlags:[`--print-config`],receivePositionalArguments:!0}}return U(e,t,[],[n])}await G({commands:{fix:{commands:[{name:`eslint`,optionFlags:[`--fix`],receivePositionalArguments:!0}],description:`Fix your project with ESLint. ${J.fileRun}`,positionalArgumentDefault:`.`,positionalArgumentMode:`optional`},init:{locationOptionFlag:!1},lint:{commands:[{name:`eslint`,optionFlags:[`--max-warnings`,`0`],receivePositionalArguments:!0}],description:`Lint your project with ESLint. ${J.fileRun}`,positionalArgumentDefault:`.`,positionalArgumentMode:`optional`},printConfig:{commands:[{execute:Y,name:Y.name}],description:`Print the effective ESLint configuration. ${J.optionalFileRun} Use \`@eslint/config-inspector\` for a more detailed view.`,positionalArgumentMode:`optional`}},description:`Kitschpatrol's ESLint shared configuration tools.`,logColor:`magenta`,logPrefix:`[ESLint]`,name:`ksc-eslint`,order:4});export{};
|
|
2
|
+
import{cosmiconfig as e}from"cosmiconfig";import{TypeScriptLoader as t}from"cosmiconfig-typescript-loader";import{execa as n}from"execa";import r from"fs-extra";import i from"node:fs";import{availableParallelism as a}from"node:os";import o from"node:path";import{PassThrough as s,Transform as c}from"node:stream";import{fileURLToPath as l}from"node:url";import{packageUp as u,packageUpSync as d}from"package-up";import f from"yargs";import{hideBin as p}from"yargs/helpers";import m from"picocolors";import{stripVTControlCharacters as h}from"node:util";import g from"@pinojs/json-colorizer";import _ from"decircular";import v from"deepmerge";import y from"json-stringify-pretty-compact";import{findWorkspacesRoot as b}from"find-workspaces";import x from"node:fs/promises";var ee=`8.3.0`;const S=[`json`,`machine`,`native`],te=S;function C(e){return typeof e==`string`&&S.includes(e)}function w(){let e=process.env.KSC_FORMAT;return C(e)?e:`native`}function ne(){let{argv:e}=process;for(let[t,n]of e.entries()){let r;n===`--format`?r=e[t+1]:n.startsWith(`--format=`)&&(r=n.slice(9)),C(r)&&(process.env.KSC_FORMAT=r)}}function re(){let{env:e}=process;if(e.NO_COLOR!==void 0&&e.NO_COLOR!==``)return!1;if(e.FORCE_COLOR!==void 0)return e.FORCE_COLOR!==`0`&&e.FORCE_COLOR!==`false`;if(e.TERM===`dumb`)return!1}function T(e,{ciColor:t=!0}={}){let n=re();return n===void 0?e.isTTY===!0||t&&!!process.env.CI:n}function E(){return w()===`json`?process.stderr:process.stdout}function D(){return w()===`machine`?m.createColors(!1):m.createColors(T(E()))}function O(e){if(!e)return{FORCE_COLOR:`0`,NO_COLOR:`1`};let t=process.env.FORCE_COLOR;return t===void 0||t===``?{FORCE_COLOR:`1`}:{}}function ie(e,t){let n=o.isAbsolute(e)?e:o.resolve(t,e),r=o.relative(process.cwd(),n);return r===``?`.`:r}const ae=/\s*\n\s*/gv,oe=/\r?\n/v;function se(e){let t=e.message.replaceAll(ae,` `),n=e.rule===void 0?e.tool:`${e.tool}/${e.rule}`;return e.file===void 0?`${e.severity}: ${t} [${n}]`:`${e.file}:${e.line??1}:${e.column??1}: ${e.severity}: ${t} [${n}]`}function ce(e,t){let n=(e.file??``).localeCompare(t.file??``);if(n!==0)return n;let r=(e.line??0)-(t.line??0);return r===0?(e.column??0)-(t.column??0):r}function le(e,t){let n=t.toSorted(ce);return{cwd:process.cwd(),diagnostics:n,success:e.every(e=>e.exitCode===0),summary:{errors:n.filter(e=>e.severity===`error`).length,infos:n.filter(e=>e.severity===`info`).length,warnings:n.filter(e=>e.severity===`warning`).length},tools:e,version:1}}function k(e){return h(e).split(oe).map(e=>e.trimEnd()).filter(e=>e.trim().length>0)}function A(e){return e instanceof Error&&`exitCode`in e&&typeof e.exitCode==`number`}function j(e){return T(process.stdout,{ciColor:!1})?de(e):ue(e)}function ue(e){return y(_(e),{indent:2,replacer(e,t){return typeof t==`function`?t.name:t}})}function de(e){return g(ue(e),{colors:{BRACKET:`gray`}})}const fe=(e,t,n)=>{let r=[...e];for(let[i,a]of t.entries())r[i]===void 0?r[i]=n.cloneUnlessOtherwiseSpecified(a,n):n.isMergeableObject(a)?r[i]=M(e[i],a,n):e.includes(a)||r.push(a);return r};function M(e,t,n={arrayMerge:fe}){return v(e,t,n)}function N(e){let{tasks:t}=e;return Array.isArray(t)?t:[]}function pe(e,t){let n=[...N(e)];for(let e of N(t)){let t=n.findIndex(t=>t.label!==void 0&&t.label===e.label);t===-1?n.push(e):n[t]=e}return{...e,...t,tasks:n}}function P(){let e=d();if(e===void 0)throw Error(`No package.json found.`);return o.dirname(e)}function F(){let e=b();return e===null?P():o.resolve(e.location)}function I(e){if(e===`workspace-root`)return F();if(e===`package-dir`)return P();if(typeof e==`string`){if(!r.pathExistsSync(e))throw Error(`Custom cwd directory does not exist: ${e}`);return e}return process.cwd()}async function me(e,t){try{let{default:n}=await import(`prettier`),r=await n.resolveConfig(e),i=await n.format(t,{filepath:e,...r});await x.writeFile(e,i,`utf8`)}catch{console.warn(`Skipped formatting ${e} since Prettier is not installed.`)}}async function L(e){try{await me(e,await x.readFile(e,`utf8`))}catch{}}const R=/\r?\n/v;function z(e){let t=``,n=t=>t.filter(t=>t.trim()!==``&&!e(h(t))).map(e=>`${e}\n`).join(``);return new c({flush(e){e(void 0,n([t]))},transform(e,r,i){let a=(t+e.toString()).split(R);t=a.pop()??``,i(void 0,n(a))}})}function B(e,t){let n=w()===`native`?e:void 0,r=n===void 0||n===``?``:t===void 0?n:D()[t](n),i=``,a=e=>e.filter(e=>e.trim().length>0).map(e=>r===``?`${e}\n`:`${r} ${e}\n`).join(``);return new c({flush(e){e(void 0,a([i]))},transform(e,t,n){let r=(i+e.toString()).split(R);i=r.pop()??``,n(void 0,a(r))}})}async function he(e){let t=[];return new Promise((n,r)=>{e.on(`data`,e=>{t.push(e)}),e.on(`error`,e=>{r(e)}),e.on(`end`,()=>{n(Buffer.concat(t).toString(`utf8`))})})}function V(e,t){return t===1?e:e+`s`}async function H(e){return typeof e==`function`?e():e}async function ge(e,t,n,r,i){let a;if(r.logPrefix===void 0)a=e;else{let t=B(r.logPrefix,r.logColor);t.pipe(e),a=t}i&&a.write(D().bold(`Running: "${r.name}() with Positional arguments: ${String(t)} and Option flags: ${String(n)}"`)+`
|
|
3
|
+
`);try{return await r.execute(a,t,n)}catch(e){return console.error(String(e)),1}}function U(e,t,n,r,i){return[...e.subcommands??[],...e.receiveOptionFlags?n:[],...r??[],...i&&e.cache!==void 0?[...e.cache.flags,`--cache-location`,o.join(F(),`node_modules`,`.cache`,`ksc`,e.cache.name)]:[],...e.receivePositionalArguments?t:[],...e.positionalArguments??[]]}async function _e(e,t,r,i,a,o){let c=1,l;if(i.logPrefix===void 0)l=e;else{let t=B(i.logPrefix,i.logColor);t.pipe(e),l=t}let u=U(i,t,r,i.optionFlags,a),d=I(i.cwdOverride);o&&l.write(`Running: "${i.name} ${u.join(` `)}"\n`);let f=i.prettyJsonOutput?new s:l,p=O(w()===`native`&&i.prettyJsonOutput!==!0&&T(E()));try{let e=n(i.name,u,{cwd:d,env:{...p},preferLocal:!0,reject:!1,stdin:`inherit`});if(i.outputFilter){let t=z(i.outputFilter),n=z(i.outputFilter);e.stdout.pipe(t).pipe(f,{end:!1}),e.stderr.pipe(n).pipe(f,{end:!1})}else e.stdout.pipe(f,{end:!1}),e.stderr.pipe(f,{end:!1});let t=await e;if(i.prettyJsonOutput){f.end();let e=await he(f),t=j(JSON.parse(e)).split(`
|
|
4
|
+
`);for(let e of t)l.write(`${e}\n`)}c=t.exitCode??1}catch(e){console.error(`${i.name} failed with error:`),console.error(e),A(e)&&(c=typeof e.exitCode==`number`?e.exitCode:1)}return c}function W(e){return`execute`in e}function G(e){return`kind`in e}async function K(e,t,r,i,a){let o=U(r,e,t,r.collect?.optionFlags??r.optionFlags,i),s=I(r.cwdOverride);try{let e=n(r.name,o,{cwd:s,env:O(!1),preferLocal:!0,reject:!1,stdin:`inherit`});a!==void 0&&e.stderr.pipe(a,{end:!1});let t=await e;return{cwd:s,exitCode:t.exitCode??1,stderr:t.stderr,stdout:t.stdout}}catch(e){return console.error(`${r.name} failed with error:`),console.error(e),{cwd:s,exitCode:A(e)&&typeof e.exitCode==`number`?e.exitCode:1,stderr:``,stdout:``}}}function ve(e){return typeof e==`object`&&!!e&&`version`in e&&e.version===1&&`diagnostics`in e&&Array.isArray(e.diagnostics)&&`tools`in e&&Array.isArray(e.tools)}async function ye(e,t,n,r,i){let a=Date.now(),o=()=>Date.now()-a;if(W(r)){if(r.collect!==void 0)try{let{diagnostics:e,exitCode:i,unparsed:a}=await r.collect(t,n);return{diagnostics:e,exitCode:i,tools:[{durationMs:o(),exitCode:i,name:r.name,unparsed:a}]}}catch(e){return{diagnostics:[],exitCode:1,tools:[{durationMs:o(),exitCode:1,name:r.name,unparsed:[String(e)]}]}}let e=``,i=new s;i.on(`data`,t=>{e+=t.toString()});let a;try{a=await r.execute(i,t,n)}catch(t){e+=`\n${String(t)}`,a=1}return{diagnostics:[],exitCode:a,tools:[{durationMs:o(),exitCode:a,name:r.name,unparsed:k(e)}]}}if(G(r))throw Error(`Command groups must be expanded before collection`);if(r.outputFormatAware){let a=await K(t,n,r,i,e);try{let e=JSON.parse(a.stdout);if(!ve(e))throw Error(`Child output is not a lint report`);return{diagnostics:e.diagnostics,exitCode:a.exitCode,tools:e.tools}}catch{return{diagnostics:[],exitCode:a.exitCode,tools:[{durationMs:o(),exitCode:a.exitCode,name:r.name,unparsed:k(a.stdout)}]}}}let c=await K(t,n,r,i);if(r.collect!==void 0)try{let{diagnostics:e,unparsed:t}=r.collect.parse(c);return{diagnostics:e,exitCode:c.exitCode,tools:[{durationMs:o(),exitCode:c.exitCode,name:r.name,unparsed:t}]}}catch(e){return{diagnostics:[],exitCode:c.exitCode,tools:[{durationMs:o(),exitCode:c.exitCode,name:r.name,unparsed:[...k(c.stdout),...k(c.stderr),String(e)]}]}}return{diagnostics:[],exitCode:c.exitCode,tools:[{durationMs:o(),exitCode:c.exitCode,name:r.name,unparsed:[...k(c.stdout),...k(c.stderr)]}]}}const be=/^ksc-/v;function q(e){return e.replace(be,``)}function J(e){return e===void 0||e.length===0?[]:e.flatMap(e=>e.split(`,`)).map(e=>q(e.trim()))}function Y(e){return e.option(`skip`,{array:!0,describe:`Tool names to skip (with or without "ksc-" prefix).`,type:`string`})}function X(e){return e.option(`format`,{choices:te,default:`native`,describe:`Output format: "native" streams each tool's own output, "machine" prints one parseable line per issue for editor problem matchers, "json" prints an aggregate report.`})}function Z(e){return e.option(`cache`,{boolean:!0,default:!0,describe:`Use tool-native caches stored below node_modules/.cache/ksc at the workspace root. Disable with --no-cache.`})}function xe(e,t){return t===`native`||t===`machine`&&!W(e)&&!G(e)&&e.outputFormatAware===!0}function Se(e,t){for(let n of t.diagnostics)e.write(`${se(n)}\n`);for(let n of t.tools)for(let t of n.unparsed)e.write(`${t}\n`)}function Ce(){return Math.min(4,a())}var we=class{concurrency;active=0;queue=[];constructor(e){this.concurrency=e}async run(e){this.active>=this.concurrency&&await new Promise(e=>{this.queue.push(e)}),this.active+=1;try{return await e()}finally{--this.active,this.queue.shift()?.()}}};async function Te(e){let t=e.cache??!1,n=e.concurrency??Ce();if(!Number.isInteger(n)||n<1)throw Error(`Concurrency must be a positive integer.`);return t&&await r.ensureDir(o.join(F(),`node_modules`,`.cache`,`ksc`)),{cache:t,scheduler:new we(n)}}function Ee(e,t){return e.positionalArgumentMode===`none`?[]:t.length>0?t:e.positionalArgumentDefault===void 0?[]:[e.positionalArgumentDefault]}function De(e,t){if(t.logPrefix===void 0)return e;let n=B(t.logPrefix,t.logColor);return n.pipe(e),n}async function Oe(e,t){if(G(e)){if(t.nativeVerbose){let n=[e.subcommand,...t.positionalArguments].join(` `);t.logStream.write(`Running: "${e.name} ${n}"\n`)}let n=De(t.logStream,e);try{let r=await ke(await H(e.commands),{...t,logStream:n,nativeVerbose:e.verbose,positionalArguments:Ee(e,t.positionalArguments)},e.parallel===!0);return{diagnostics:r.flatMap(({diagnostics:e})=>e),exitCode:+!r.every(({exitCode:e})=>e===0),machineOutcomes:r.flatMap(({machineOutcomes:e})=>e),name:e.name,tools:r.flatMap(({tools:e})=>e)}}catch(r){let i=String(r),a={durationMs:0,exitCode:1,name:e.name,unparsed:[i]};return t.format===`native`&&n.write(`${i}\n`),{diagnostics:[],exitCode:1,machineOutcomes:[{diagnostics:[],exitCode:1,tools:[a]}],name:e.name,tools:[a]}}}return t.scheduler.run(async()=>{if(xe(e,t.format))return{diagnostics:[],exitCode:await(W(e)?ge(t.logStream,t.positionalArguments,t.optionFlags,e,t.nativeVerbose):_e(t.logStream,t.positionalArguments,t.optionFlags,e,t.cache,t.nativeVerbose)),machineOutcomes:[],name:e.name,tools:[]};let n=await ye(t.logStream,t.positionalArguments,t.optionFlags,e,t.cache);return{diagnostics:n.diagnostics,exitCode:n.exitCode,machineOutcomes:[n],name:e.name,tools:n.tools}})}async function ke(e,t,n){if(!n||t.scheduler.concurrency===1){let n=[];for(let r of e)n.push(await Oe(r,t));return n}await Promise.resolve();let r=new Map;for(let[t,n]of e.entries()){let e=n.stage??0,i=r.get(e)??[];i.push({command:n,index:t}),r.set(e,i)}let i=Array.from({length:e.length}),a=r.keys().toArray().toSorted((e,t)=>e-t);for(let e of a){let n=r.get(e)??[],a=await Promise.all(n.map(async({command:e,index:n})=>({index:n,outcome:await Oe(e,t)})));for(let{index:e,outcome:t}of a)i[e]=t}return i.filter(e=>e!==void 0)}function Ae(e,t,n){let r=[],i=[];for(let e of t)n.length>0&&n.includes(q(e.name))?i.push(e):r.push(e);if(n.length>0){let r=new Set(i.map(e=>q(e.name))),a=n.filter(e=>!r.has(e));if(a.length>0){let n=t.map(e=>q(e.name)).join(`, `);e.write(`⚠️ ${D().yellow(`Unrecognized --skip ${V(`value`,a.length)}: ${a.join(`, `)}. Available: ${n}`)}\n`)}}return{commandsToRun:r,skippedCommands:i}}async function Q(e,t,n,r,i,a,o,s=`native`){let c=typeof s==`string`?{}:s,l=typeof s==`string`?s:c.format??`native`,{commandsToRun:u,skippedCommands:d}=Ae(e,r,o??[]),f=l===`native`&&i,{cache:p,scheduler:m}=await Te(c),h=await ke(u,{cache:p,format:l,logStream:e,nativeVerbose:f,optionFlags:n,positionalArguments:t,scheduler:m},c.parallel===!0),g=h.map(({exitCode:e,name:t})=>({exitCode:e,name:t})),_=h.flatMap(({tools:e})=>e),v=h.flatMap(({diagnostics:e})=>e);if(l===`machine`)for(let t of h)for(let n of t.machineOutcomes)Se(e,n);let y=r.length,b=D();if(l===`native`&&d.length>0){let t=d.map(({name:e})=>e),n=b.bold(`${t.length} / ${y} ${V(`Command`,t.length)} Skipped:`);e.write(`⏭️ ${b.dim(n)} ${b.dim(t.join(`, `))}\n`)}if(l===`native`&&a){let t=g.filter(({exitCode:e})=>e===0).map(({name:e})=>e),n=g.filter(({exitCode:e})=>e!==0).map(({name:e})=>e);if(t.length>0){let n=b.bold(`${t.length} / ${y} ${V(`Command`,t.length)} Succeeded:`);e.write(`✅ ${b.green(n)} ${b.green(t.join(`, `))}\n`)}if(n.length>0){let t=b.bold(`${n.length} / ${y} ${V(`Command`,n.length)} Failed:`);e.write(`❌ ${b.red(t)} ${b.red(n.join(`, `))}\n`)}}return{exitCode:+!g.every(({exitCode:e})=>e===0),report:l===`json`?le(_,v):void 0}}async function je(e,t,n,a){let s=await u();if(s===void 0)throw Error("The `init` command must be used in a directory with a package.json file");let c=await u({cwd:l(import.meta.url)});if(c===void 0)return e.write(`Error: The script being called was not in a package, weird.
|
|
5
|
+
`),1;let d=o.join(o.dirname(c),`init`),f=o.dirname(s),p=(t===`file`||t===`package`)&&n!==void 0&&a!==void 0;try{if(p){let n=Object.keys(a)[0],i=r.readJsonSync(s);if(t===`package`){e.write(`Merging: \nPackage config key "${n}" → "${f}" (Because --location is set to "package")\n`);let t=M(i,a);r.writeJSONSync(s,t,{spaces:` `}),await L(s)}else n!==void 0&&Object.keys(i).includes(n)&&(e.write(`Deleting: \nPackage config key "${n}" in "${f}" (Because --location is set to "file")\n`),delete i[n],r.writeJSONSync(s,i,{spaces:` `}),await L(s))}if(!await r.pathExists(d))return 0;if((await r.readdir(d)).length===0)return e.write(`Source directory "${d}" is empty.\n`),0;e.write(`Adding initial configuration files from:\n"${d}" → "${f}"\n`),await r.copy(d,f,{async filter(a,s){let c=i.statSync(a).isFile(),l=i.existsSync(s);if(c){if(p&&t===`package`&&a.includes(n))return l?(e.write(`Deleting: \n"${a}" → "${s}" (Because --location is set to "package")\n`),r.removeSync(s)):e.write(`Skipping: \n"${a}" → "${s}" (Because --location is set to "package")\n`),!1;if(l&&(s.includes(`.vscode/`)||s.includes(`package.json`))&&o.extname(s)===`.json`){e.write(`Merging: \n"${a}" → "${s}"\n`);let t=r.readJSONSync(a),n=r.readJSONSync(s),i=s.endsWith(`.vscode/tasks.json`)?pe(n,t):M(n,t);return r.writeJSONSync(s,i,{spaces:` `}),await L(s),!1}return l?(e.write(`Overwriting: \n"${a}" → "${s}"\n`),await L(s),!0):(e.write(`Copying: \n"${a}" → "${s}"\n`),await L(s),!0)}return!0},overwrite:!0})}catch(e){return console.error(String(e)),1}return 0}async function Me(e){let{commands:{fix:t,init:n,lint:r,printConfig:i},description:a,logColor:o,logPrefix:s,name:c,showSummary:l,verbose:u}=e;ne();let d=B(s,o);d.pipe(E());let m=f(p(process.argv)).scriptName(c).usage(`$0 <command>`,a);n!==void 0&&m.command({builder(e){let t=n.locationOptionFlag?e.option(`location`,{choices:[`file`,`package`],default:`file`,describe:`Where to store the configuration.`,type:`string`}):e;return l?Y(t):t},command:`init`,describe:n.description??`Initialize by copying starter config files to your project root${n.locationOptionFlag?` or to your package.json file.`:`.`}`,async handler(e){let t=n.locationOptionFlag?e.location:void 0,r=J(e.skip),{exitCode:i}=await Q(d,[],t===void 0?[]:[`--location`,t],[{async execute(e,t,r){return je(e,r.at(1),n.configFile,n.configPackageJson)},name:`copyAndMergeInitFiles`},...n.commands??[]],void 0,void 0,r);process.exitCode=i}}),r!==void 0&&m.command({builder(e){let t=Z(X(r.positionalArgumentMode===`none`?e:e.positional(`files`,{array:!0,...r.positionalArgumentDefault!==void 0&&{default:r.positionalArgumentDefault},describe:`Files or glob pattern to lint.`,type:`string`})));return l?Y(t):t},command:r.positionalArgumentMode===`none`?`lint`:r.positionalArgumentMode===`optional`?`lint [files..]`:`lint <files..>`,describe:r.description,async handler(e){let t=e.files??[],n=J(e.skip),i=w(),{exitCode:a,report:o}=await Q(d,t,[],await H(r.commands),u,l,n,{cache:e.cache,format:i,parallel:r.parallel});o!==void 0&&process.stdout.write(`${j(o)}\n`),process.exitCode=a}}),t!==void 0&&m.command({builder(e){let n=Z(X(t.positionalArgumentMode===`none`?e:e.positional(`files`,{array:!0,...t.positionalArgumentDefault!==void 0&&{default:t.positionalArgumentDefault},describe:`Files or glob pattern to fix.`,type:`string`})));return l?Y(n):n},command:t.positionalArgumentMode===`none`?`fix`:t.positionalArgumentMode===`optional`?`fix [files..]`:`fix <files..>`,describe:t.description,async handler(e){let n=e.files??[],r=J(e.skip),i=w(),{exitCode:a,report:o}=await Q(d,n,[],await H(t.commands),void 0,void 0,r,{cache:e.cache,format:i,parallel:t.parallel});o!==void 0&&process.stdout.write(`${j(o)}\n`),process.exitCode=a}}),i!==void 0&&m.command({builder(e){let t=i.positionalArgumentMode===`none`?e:e.positional(`file`,{...i.positionalArgumentDefault!==void 0&&{default:i.positionalArgumentDefault},describe:`File or glob pattern to print configuration for.`,type:`string`});return l?Y(t):t},command:i.positionalArgumentMode===`none`?`print-config`:i.positionalArgumentMode===`optional`?`print-config [file]`:`print-config <file>`,describe:i.description,async handler(e){let t=e.file??void 0,n=t===void 0?[]:[t],r=J(e.skip),{exitCode:a}=await Q(d,n,[],await H(i.commands),u,l,r);process.exitCode=a}}),m.alias(`h`,`help`),m.version(ee),m.alias(`v`,`version`),m.help(),m.wrap(process.stdout.isTTY?Math.min(120,m.terminalWidth()):0),await m.parseAsync()}function Ne(e){return{async execute(t){let n=await Pe(e);if(n===void 0)return 1;let{config:r,filepath:i,isEmpty:a}=n;if(t.write(`Found ${e} configuration at "${i}"\n`),a)return t.write(`Configuration is empty.
|
|
6
|
+
`),0;let o=j(r).split(`
|
|
7
|
+
`);for(let e of o)t.write(`${e}\n`);return 0},name:`Cosmiconfig ${e}`}}async function Pe(n){let r=e(n,{loaders:{".ts":t()},searchStrategy:`project`});try{let e=await r.search();if(e===null){console.error(`No ${n} configuration found.`);return}return e}catch(e){console.error(`Error while searching for ${n} configuration:`,e);return}}const $={fileRun:`Matches files below the current working directory by default.`,monorepoRun:`In a monorepo, it will also run in all packages below the current working directory.`,monorepoSearch:`Searches up to the root of a monorepo if necessary.`,multiArgumentCaveat:`Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package scope.`,multiOptionCaveat:`Will use option flags where possible if provided, but some of the invoked tools will ignore them.`,optionalFileRun:`Package-scoped by default, file-scoped if a file argument is provided.`,packageRun:`Package-scoped.`,packageSearch:`Package-scoped.`};async function Fe(e,t){let n,[r]=t;if(r===void 0)n=Ne(`eslint`);else{let t=o.join(process.cwd(),r);e.write(`Showing configuration for file: ${t}\n`),n={name:`eslint`,optionFlags:[`--print-config`],receivePositionalArguments:!0}}let{exitCode:i}=await Q(e,t,[],[n]);return i}function Ie(e){let t;try{t=JSON.parse(e.stdout)}catch{return{diagnostics:[],unparsed:[...k(e.stdout),...k(e.stderr)]}}let n=[];for(let r of t)for(let t of r.messages)n.push({column:t.column,endColumn:t.endColumn,endLine:t.endLine,file:ie(r.filePath,e.cwd),line:t.line,message:t.message,rule:t.ruleId??void 0,severity:t.fatal===!0||t.severity===2?`error`:`warning`,tool:`eslint`});return{diagnostics:n,unparsed:k(e.stderr)}}await Me({commands:{fix:{commands:[{cache:{flags:[`--cache`,`--cache-strategy`,`content`],name:`eslint`},collect:{optionFlags:[`--fix`,`--max-warnings`,`0`,`--format`,`json`],parse:Ie},name:`eslint`,optionFlags:[`--fix`,`--max-warnings`,`0`],receivePositionalArguments:!0}],description:`Fix your project with ESLint. ${$.fileRun}`,positionalArgumentDefault:`.`,positionalArgumentMode:`optional`},init:{locationOptionFlag:!1},lint:{commands:[{cache:{flags:[`--cache`,`--cache-strategy`,`content`],name:`eslint`},collect:{optionFlags:[`--max-warnings`,`0`,`--format`,`json`],parse:Ie},name:`eslint`,optionFlags:[`--max-warnings`,`0`],receivePositionalArguments:!0}],description:`Lint your project with ESLint. ${$.fileRun}`,positionalArgumentDefault:`.`,positionalArgumentMode:`optional`},printConfig:{commands:[{execute:Fe,name:`eslint-config`}],description:`Print the effective ESLint configuration. ${$.optionalFileRun} Use \`@eslint/config-inspector\` for a more detailed view.`,positionalArgumentMode:`optional`}},description:`Kitschpatrol's ESLint shared configuration tools.`,logColor:`magenta`,logPrefix:`[ESLint]`,name:`ksc-eslint`,order:4});export{};
|