lintcn 0.0.1 → 0.2.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/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +157 -5
- package/dist/cache.d.ts +9 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +88 -0
- package/dist/cli.js +71 -3
- package/dist/codegen.d.ts +18 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +607 -0
- package/dist/commands/add.d.ts +2 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +101 -0
- package/dist/commands/lint.d.ts +10 -0
- package/dist/commands/lint.d.ts.map +1 -0
- package/dist/commands/lint.js +78 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +24 -0
- package/dist/commands/remove.d.ts +2 -0
- package/dist/commands/remove.d.ts.map +1 -0
- package/dist/commands/remove.js +31 -0
- package/dist/discover.d.ts +16 -0
- package/dist/discover.d.ts.map +1 -0
- package/dist/discover.js +44 -0
- package/dist/exec.d.ts +10 -0
- package/dist/exec.d.ts.map +1 -0
- package/dist/exec.js +34 -0
- package/dist/hash.d.ts +5 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +33 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +5 -0
- package/package.json +12 -9
- package/src/cache.ts +106 -0
- package/src/cli.ts +80 -2
- package/src/codegen.ts +640 -0
- package/src/commands/add.ts +118 -0
- package/src/commands/lint.ts +110 -0
- package/src/commands/list.ts +33 -0
- package/src/commands/remove.ts +41 -0
- package/src/discover.ts +69 -0
- package/src/exec.ts +50 -0
- package/src/hash.ts +45 -0
- package/src/index.ts +7 -1
- package/src/paths.ts +7 -0
package/src/cli.ts
CHANGED
|
@@ -1,4 +1,82 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// lintcn — the shadcn for type-aware TypeScript lint rules.
|
|
4
|
+
// Add rules by URL, compile, and run them via tsgolint.
|
|
5
|
+
|
|
6
|
+
import { goke } from 'goke'
|
|
7
|
+
import { createRequire } from 'node:module'
|
|
8
|
+
import { addRule } from './commands/add.ts'
|
|
9
|
+
import { lint, buildBinary } from './commands/lint.ts'
|
|
10
|
+
import { listRules } from './commands/list.ts'
|
|
11
|
+
import { removeRule } from './commands/remove.ts'
|
|
12
|
+
import { DEFAULT_TSGOLINT_VERSION } from './cache.ts'
|
|
13
|
+
|
|
14
|
+
const require = createRequire(import.meta.url)
|
|
15
|
+
const packageJson = require('../package.json') as { version: string }
|
|
16
|
+
|
|
17
|
+
const cli = goke('lintcn')
|
|
18
|
+
|
|
19
|
+
cli
|
|
20
|
+
.command('add <url>', 'Add a rule by URL. Fetches the .go file and copies it into .lintcn/')
|
|
21
|
+
.example('# Add a rule from GitHub')
|
|
22
|
+
.example('lintcn add https://github.com/user/repo/blob/main/rules/no_floating_promises.go')
|
|
23
|
+
.example('# Add from raw URL')
|
|
24
|
+
.example('lintcn add https://raw.githubusercontent.com/user/repo/main/rules/no_unused_result.go')
|
|
25
|
+
.action(async (url) => {
|
|
26
|
+
await addRule(url)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
cli
|
|
30
|
+
.command('remove <name>', 'Remove an installed rule from .lintcn/')
|
|
31
|
+
.example('lintcn remove no-floating-promises')
|
|
32
|
+
.action((name) => {
|
|
33
|
+
removeRule(name)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
cli
|
|
37
|
+
.command('list', 'List all installed rules')
|
|
38
|
+
.action(() => {
|
|
39
|
+
listRules()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
cli
|
|
43
|
+
.command('lint', 'Build custom tsgolint binary and run it against the project')
|
|
44
|
+
.option('--rebuild', 'Force rebuild even if cached binary exists')
|
|
45
|
+
.option('--tsconfig <path>', 'Path to tsconfig.json')
|
|
46
|
+
.option('--list-files', 'List matched files')
|
|
47
|
+
.option('--tsgolint-version [version]', 'Override the pinned tsgolint version (tag or commit). For testing unreleased tsgolint versions.')
|
|
48
|
+
.action(async (options) => {
|
|
49
|
+
const tsgolintVersion = (options.tsgolintVersion as string) || DEFAULT_TSGOLINT_VERSION
|
|
50
|
+
const passthroughArgs: string[] = []
|
|
51
|
+
if (options.tsconfig) {
|
|
52
|
+
passthroughArgs.push('--tsconfig', options.tsconfig as string)
|
|
53
|
+
}
|
|
54
|
+
if (options.listFiles) {
|
|
55
|
+
passthroughArgs.push('--list-files')
|
|
56
|
+
}
|
|
57
|
+
// pass through anything after --
|
|
58
|
+
const doubleDash = options['--']
|
|
59
|
+
if (doubleDash && Array.isArray(doubleDash)) {
|
|
60
|
+
passthroughArgs.push(...doubleDash)
|
|
61
|
+
}
|
|
62
|
+
const exitCode = await lint({
|
|
63
|
+
rebuild: !!options.rebuild,
|
|
64
|
+
tsgolintVersion,
|
|
65
|
+
passthroughArgs,
|
|
66
|
+
})
|
|
67
|
+
process.exit(exitCode)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
cli
|
|
71
|
+
.command('build', 'Build the custom tsgolint binary without running it')
|
|
72
|
+
.option('--rebuild', 'Force rebuild even if cached binary exists')
|
|
73
|
+
.option('--tsgolint-version [version]', 'Override the pinned tsgolint version (tag or commit). For testing unreleased tsgolint versions.')
|
|
74
|
+
.action(async (options) => {
|
|
75
|
+
const tsgolintVersion = (options.tsgolintVersion as string) || DEFAULT_TSGOLINT_VERSION
|
|
76
|
+
const binaryPath = await buildBinary({ rebuild: !!options.rebuild, tsgolintVersion })
|
|
77
|
+
console.log(binaryPath)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
cli.help()
|
|
81
|
+
cli.version(packageJson.version)
|
|
82
|
+
cli.parse()
|