lintcn 0.7.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.7.1
2
+
3
+ 1. **`lintcn lint` / `lintcn build` exit 0 when `.lintcn/` not found** — instead of throwing and exiting 1, they now print a helpful message and exit cleanly. Useful when running lintcn in CI on repos that haven't set up rules yet.
4
+
5
+ 2. **Snapshot files land in `.lintcn/<rule>/__snapshots__/`** — bumped tsgolint to `518fa0d`. Rule tests now write snapshots relative to the test package directory instead of the cached tsgolint source, so they're committed alongside your rule and survive `lintcn clean`. Set `TSGOLINT_SNAPSHOT_CWD=true` when running `go test` to get this behavior.
6
+
1
7
  ## 0.7.0
2
8
 
3
9
  1. **`lintcn lint --fix`** — automatically apply fixes in-place. Collects diagnostics per file, applies fixes via the Go runner, and only reports what couldn't be auto-fixed:
package/dist/cache.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const DEFAULT_TSGOLINT_VERSION = "23190a08a6315eba8ef11818fc1c38d7b01c9e10";
1
+ export declare const DEFAULT_TSGOLINT_VERSION = "518fa0d395effb07a45070643a0cb1a9cf202ce9";
2
2
  /** Validate version string to prevent path traversal attacks.
3
3
  * Only allows alphanumeric chars, dots, underscores, and hyphens. */
4
4
  export declare function validateVersion(version: string): void;
package/dist/cache.js CHANGED
@@ -14,9 +14,9 @@ import { pipeline } from 'node:stream/promises';
14
14
  import { extract } from 'tar';
15
15
  import { execAsync } from "./exec.js";
16
16
  // Pinned tsgolint fork commit — updated with each lintcn release.
17
- // Uses remorses/tsgolint fork which adds internal/runner.Run().
18
- // Only 1 commit on top of upstream — zero modifications to existing files.
19
- export const DEFAULT_TSGOLINT_VERSION = '23190a08a6315eba8ef11818fc1c38d7b01c9e10';
17
+ // Uses remorses/tsgolint fork which adds internal/runner.Run() and
18
+ // TSGOLINT_SNAPSHOT_CWD env var for cwd-relative test snapshots.
19
+ export const DEFAULT_TSGOLINT_VERSION = '518fa0d395effb07a45070643a0cb1a9cf202ce9';
20
20
  // Pinned typescript-go base commit from microsoft/typescript-go (before patches).
21
21
  // Patches from tsgolint/patches/ are applied on top during setup.
22
22
  // Must be updated when DEFAULT_TSGOLINT_VERSION changes.
package/dist/cli.js CHANGED
@@ -9,6 +9,7 @@ import { listRules } from "./commands/list.js";
9
9
  import { removeRule } from "./commands/remove.js";
10
10
  import { clean } from "./commands/clean.js";
11
11
  import { DEFAULT_TSGOLINT_VERSION } from "./cache.js";
12
+ import { findLintcnDir } from "./paths.js";
12
13
  const require = createRequire(import.meta.url);
13
14
  const packageJson = require('../package.json');
14
15
  const cli = goke('lintcn');
@@ -72,6 +73,10 @@ cli
72
73
  .option('--rebuild', 'Force rebuild even if cached binary exists')
73
74
  .option('--tsgolint-version [version]', 'Override the pinned tsgolint version (tag or commit). For testing unreleased tsgolint versions.')
74
75
  .action(async (options) => {
76
+ if (!findLintcnDir()) {
77
+ console.log('No .lintcn/ directory found. Run `lintcn add <url>` to add rules.');
78
+ return;
79
+ }
75
80
  const tsgolintVersion = options.tsgolintVersion || DEFAULT_TSGOLINT_VERSION;
76
81
  const binaryPath = await buildBinary({ rebuild: !!options.rebuild, tsgolintVersion });
77
82
  console.log(binaryPath);
@@ -1 +1 @@
1
- {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../src/commands/lint.ts"],"names":[],"mappings":"AAwBA,wBAAsB,WAAW,CAAC,EAChC,OAAO,EACP,eAAe,GAChB,EAAE;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;CACxB,GAAG,OAAO,CAAC,MAAM,CAAC,CAkElB;AAED,wBAAsB,IAAI,CAAC,EACzB,OAAO,EACP,eAAe,EACf,eAAe,EACf,WAAW,GACZ,EAAE;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoClB"}
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../src/commands/lint.ts"],"names":[],"mappings":"AAwBA,wBAAsB,WAAW,CAAC,EAChC,OAAO,EACP,eAAe,GAChB,EAAE;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;CACxB,GAAG,OAAO,CAAC,MAAM,CAAC,CAkElB;AAED,wBAAsB,IAAI,CAAC,EACzB,OAAO,EACP,eAAe,EACf,eAAe,EACf,WAAW,GACZ,EAAE;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyClB"}
@@ -3,7 +3,7 @@
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import { spawn } from 'node:child_process';
6
- import { requireLintcnDir } from "../paths.js";
6
+ import { requireLintcnDir, findLintcnDir } from "../paths.js";
7
7
  import { discoverRules } from "../discover.js";
8
8
  import { generateBuildWorkspace, generateEditorGoFiles } from "../codegen.js";
9
9
  import { ensureTsgolintSource, validateVersion, cachedBinaryExists, getBinaryPath, getBuildDir, getBinDir } from "../cache.js";
@@ -75,6 +75,10 @@ export async function buildBinary({ rebuild, tsgolintVersion, }) {
75
75
  return binaryPath;
76
76
  }
77
77
  export async function lint({ rebuild, tsgolintVersion, passthroughArgs, allWarnings, }) {
78
+ if (!findLintcnDir()) {
79
+ console.log('No .lintcn/ directory found. Run `lintcn add <url>` to add rules.');
80
+ return 0;
81
+ }
78
82
  const binaryPath = await buildBinary({ rebuild, tsgolintVersion });
79
83
  // Discover rules to inject --warn flags for warning-severity rules.
80
84
  // buildBinary already discovered rules for compilation, but we need the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lintcn",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "description": "The shadcn for type-aware TypeScript lint rules. Browse, pick, and copy rules into your project.",
6
6
  "bin": "dist/cli.js",
package/src/cache.ts CHANGED
@@ -16,9 +16,9 @@ import { extract } from 'tar'
16
16
  import { execAsync } from './exec.ts'
17
17
 
18
18
  // Pinned tsgolint fork commit — updated with each lintcn release.
19
- // Uses remorses/tsgolint fork which adds internal/runner.Run().
20
- // Only 1 commit on top of upstream — zero modifications to existing files.
21
- export const DEFAULT_TSGOLINT_VERSION = '23190a08a6315eba8ef11818fc1c38d7b01c9e10'
19
+ // Uses remorses/tsgolint fork which adds internal/runner.Run() and
20
+ // TSGOLINT_SNAPSHOT_CWD env var for cwd-relative test snapshots.
21
+ export const DEFAULT_TSGOLINT_VERSION = '518fa0d395effb07a45070643a0cb1a9cf202ce9'
22
22
 
23
23
  // Pinned typescript-go base commit from microsoft/typescript-go (before patches).
24
24
  // Patches from tsgolint/patches/ are applied on top during setup.
package/src/cli.ts CHANGED
@@ -11,6 +11,7 @@ import { listRules } from './commands/list.ts'
11
11
  import { removeRule } from './commands/remove.ts'
12
12
  import { clean } from './commands/clean.ts'
13
13
  import { DEFAULT_TSGOLINT_VERSION } from './cache.ts'
14
+ import { findLintcnDir } from './paths.ts'
14
15
 
15
16
  const require = createRequire(import.meta.url)
16
17
  const packageJson = require('../package.json') as { version: string }
@@ -81,6 +82,10 @@ cli
81
82
  .option('--rebuild', 'Force rebuild even if cached binary exists')
82
83
  .option('--tsgolint-version [version]', 'Override the pinned tsgolint version (tag or commit). For testing unreleased tsgolint versions.')
83
84
  .action(async (options) => {
85
+ if (!findLintcnDir()) {
86
+ console.log('No .lintcn/ directory found. Run `lintcn add <url>` to add rules.')
87
+ return
88
+ }
84
89
  const tsgolintVersion = (options.tsgolintVersion as string) || DEFAULT_TSGOLINT_VERSION
85
90
  const binaryPath = await buildBinary({ rebuild: !!options.rebuild, tsgolintVersion })
86
91
  console.log(binaryPath)
@@ -4,7 +4,7 @@
4
4
  import fs from 'node:fs'
5
5
  import path from 'node:path'
6
6
  import { spawn } from 'node:child_process'
7
- import { requireLintcnDir } from '../paths.ts'
7
+ import { requireLintcnDir, findLintcnDir } from '../paths.ts'
8
8
  import { discoverRules, type RuleMetadata } from '../discover.ts'
9
9
  import { generateBuildWorkspace, generateEditorGoFiles } from '../codegen.ts'
10
10
  import { ensureTsgolintSource, validateVersion, cachedBinaryExists, getBinaryPath, getBuildDir, getBinDir } from '../cache.ts'
@@ -107,6 +107,11 @@ export async function lint({
107
107
  passthroughArgs: string[]
108
108
  allWarnings: boolean
109
109
  }): Promise<number> {
110
+ if (!findLintcnDir()) {
111
+ console.log('No .lintcn/ directory found. Run `lintcn add <url>` to add rules.')
112
+ return 0
113
+ }
114
+
110
115
  const binaryPath = await buildBinary({ rebuild, tsgolintVersion })
111
116
 
112
117
  // Discover rules to inject --warn flags for warning-severity rules.