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.
Files changed (50) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +157 -5
  4. package/dist/cache.d.ts +9 -0
  5. package/dist/cache.d.ts.map +1 -0
  6. package/dist/cache.js +88 -0
  7. package/dist/cli.js +71 -3
  8. package/dist/codegen.d.ts +18 -0
  9. package/dist/codegen.d.ts.map +1 -0
  10. package/dist/codegen.js +607 -0
  11. package/dist/commands/add.d.ts +2 -0
  12. package/dist/commands/add.d.ts.map +1 -0
  13. package/dist/commands/add.js +101 -0
  14. package/dist/commands/lint.d.ts +10 -0
  15. package/dist/commands/lint.d.ts.map +1 -0
  16. package/dist/commands/lint.js +78 -0
  17. package/dist/commands/list.d.ts +2 -0
  18. package/dist/commands/list.d.ts.map +1 -0
  19. package/dist/commands/list.js +24 -0
  20. package/dist/commands/remove.d.ts +2 -0
  21. package/dist/commands/remove.d.ts.map +1 -0
  22. package/dist/commands/remove.js +31 -0
  23. package/dist/discover.d.ts +16 -0
  24. package/dist/discover.d.ts.map +1 -0
  25. package/dist/discover.js +44 -0
  26. package/dist/exec.d.ts +10 -0
  27. package/dist/exec.d.ts.map +1 -0
  28. package/dist/exec.js +34 -0
  29. package/dist/hash.d.ts +5 -0
  30. package/dist/hash.d.ts.map +1 -0
  31. package/dist/hash.js +33 -0
  32. package/dist/index.d.ts +7 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +6 -1
  35. package/dist/paths.d.ts +2 -0
  36. package/dist/paths.d.ts.map +1 -0
  37. package/dist/paths.js +5 -0
  38. package/package.json +12 -9
  39. package/src/cache.ts +106 -0
  40. package/src/cli.ts +80 -2
  41. package/src/codegen.ts +640 -0
  42. package/src/commands/add.ts +118 -0
  43. package/src/commands/lint.ts +110 -0
  44. package/src/commands/list.ts +33 -0
  45. package/src/commands/remove.ts +41 -0
  46. package/src/discover.ts +69 -0
  47. package/src/exec.ts +50 -0
  48. package/src/hash.ts +45 -0
  49. package/src/index.ts +7 -1
  50. package/src/paths.ts +7 -0
package/src/cli.ts CHANGED
@@ -1,4 +1,82 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- console.log('lintcn - the shadcn for type-aware TypeScript lint rules')
4
- console.log('coming soon: npx lintcn add <rule-name>')
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()