static-analysis-check 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mujan5427
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,80 @@
1
- # Temporary Holding Version
1
+ # static-analysis-check
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A CLI for linting JavaScript and TypeScript with ESLint recommended rules and finding unused files, dependencies, and exports with Knip. Powered by `eslint`, `@eslint/js`, `typescript-eslint`, and `knip`, with no custom analysis rules. The `typescript` dependency supports TypeScript parsing and linting.
4
+
5
+ ## Installation
6
+
7
+ Requires Node.js `^20.19.0 || ^22.13.0 || >=24`.
8
+
9
+ ```sh
10
+ npm install --save-dev static-analysis-check
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Lints the current directory without requiring an ESLint config.
16
+
17
+ ```sh
18
+ npx static-analysis-check lint
19
+ ```
20
+
21
+ Lint a single directory:
22
+
23
+ ```sh
24
+ npx static-analysis-check lint src
25
+ ```
26
+
27
+ Lint multiple directories:
28
+
29
+ ```sh
30
+ npx static-analysis-check lint src app components
31
+ ```
32
+
33
+ Lint a specific file:
34
+
35
+ ```sh
36
+ npx static-analysis-check lint src/index.ts
37
+ ```
38
+
39
+ Lint only TS/TSX files (quote the glob so ESLint expands it):
40
+
41
+ ```sh
42
+ npx static-analysis-check lint "src/**/*.{ts,tsx}"
43
+ ```
44
+
45
+ Apply automatic fixes:
46
+
47
+ ```sh
48
+ npx static-analysis-check lint src --fix
49
+ ```
50
+
51
+ Use a custom ESLint config:
52
+
53
+ ```sh
54
+ npx static-analysis-check lint --config eslint.config.mjs
55
+ ```
56
+
57
+ Find unused files, dependencies, and exports in the current project:
58
+
59
+ ```sh
60
+ npx static-analysis-check knip
61
+ ```
62
+
63
+ Pass Knip options directly, including a custom Knip config:
64
+
65
+ ```sh
66
+ npx static-analysis-check knip --production
67
+ npx static-analysis-check knip --config knip.json
68
+ ```
69
+
70
+ Show available commands and options:
71
+
72
+ ```sh
73
+ npx static-analysis-check --help
74
+ npx static-analysis-check lint --help
75
+ npx static-analysis-check knip --help
76
+ ```
77
+
78
+ For `lint`, use paths to limit linting to specific files or directories. Use `--config` to replace the bundled ESLint config, including environment globals when needed. Knip runs in the current project and uses its own configuration and options.
79
+
80
+ The original usage without a subcommand still runs lint, for example `npx static-analysis-check src --fix`. Use `lint ./knip` or `lint ./lint` to lint directories named after subcommands.
package/bin/cli.js ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { spawnSync } from 'node:child_process';
4
+ import { resolve } from 'node:path';
5
+ import { parseArgs } from 'node:util';
6
+ import { fileURLToPath, URL } from 'node:url';
7
+ import process from 'node:process';
8
+
9
+ async function lint(args) {
10
+ const { values, positionals } = parseArgs({
11
+ args,
12
+ allowPositionals: true,
13
+ options: {
14
+ help: { type: 'boolean', short: 'h' },
15
+ version: { type: 'boolean', short: 'v' },
16
+ fix: { type: 'boolean' },
17
+ config: { type: 'string' },
18
+ },
19
+ });
20
+
21
+ if (values.help) {
22
+ process.stdout.write(`Usage: static-analysis-check lint [paths...] [options]
23
+
24
+ Lint JS/TS using ESLint recommended rules. Paths default to '.'.
25
+ Type checking is handled by your project's build tooling, such as Next.js.
26
+
27
+ Options:
28
+ --fix Apply ESLint automatic fixes
29
+ --config <path> Replace the bundled ESLint config with a flat config
30
+ -h, --help Show help
31
+ -v, --version Show version
32
+
33
+ Exit codes: 0 = passed, 1 = check failed, 2 = configuration/runtime error.
34
+ `);
35
+ return 0;
36
+ }
37
+ if (values.version) {
38
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
39
+ process.stdout.write(`${pkg.version}\n`);
40
+ return 0;
41
+ }
42
+
43
+ const { ESLint } = await import('eslint');
44
+ const eslint = new ESLint({
45
+ overrideConfigFile: values.config
46
+ ? resolve(values.config)
47
+ : fileURLToPath(new URL('../eslint.config.js', import.meta.url)),
48
+ fix: values.fix ?? false,
49
+ });
50
+ const results = await eslint.lintFiles(positionals.length ? positionals : ['.']);
51
+ if (values.fix) await ESLint.outputFixes(results);
52
+ const formatter = await eslint.loadFormatter('stylish');
53
+ process.stdout.write(formatter.format(results));
54
+ return results.some(result => result.errorCount > 0) ? 1 : 0;
55
+ }
56
+
57
+ async function main() {
58
+ const args = process.argv.slice(2);
59
+ const [command, ...commandArgs] = args;
60
+
61
+ if (command === 'knip') {
62
+ const entry = fileURLToPath(new URL('../bin/knip.js', import.meta.resolve('knip')));
63
+ const result = spawnSync(process.execPath, [entry, ...commandArgs], { stdio: 'inherit' });
64
+ if (result.error) throw result.error;
65
+ if (result.signal) {
66
+ process.kill(process.pid, result.signal);
67
+ return 1;
68
+ }
69
+ return result.status;
70
+ }
71
+
72
+ if (command === 'lint') return lint(commandArgs);
73
+
74
+ if (command === '--help' || command === '-h') {
75
+ process.stdout.write(`Usage: static-analysis-check <command> [options]
76
+
77
+ Commands:
78
+ lint [paths...] [options] Lint JS/TS using ESLint recommended rules
79
+ knip [options] Find unused files, dependencies, and exports with Knip
80
+
81
+ Options:
82
+ -h, --help Show help
83
+ -v, --version Show package version
84
+
85
+ Run 'static-analysis-check lint --help' or 'static-analysis-check knip --help'
86
+ for command options. Without a subcommand, the original lint usage still works.
87
+ `);
88
+ return 0;
89
+ }
90
+
91
+ return lint(args);
92
+ }
93
+
94
+ try {
95
+ process.exitCode = await main();
96
+ } catch (error) {
97
+ process.stderr.write(`static-analysis-check: ${error.message}\n`);
98
+ process.exitCode = 2;
99
+ }
@@ -0,0 +1,15 @@
1
+ import js from '@eslint/js';
2
+ import tseslint from 'typescript-eslint';
3
+
4
+ export default tseslint.config(
5
+ { ignores: ['**/node_modules/**', '**/dist/**', '**/coverage/**'] },
6
+ {
7
+ files: ['**/*.{js,mjs,cjs,jsx}'],
8
+ extends: [js.configs.recommended],
9
+ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
10
+ },
11
+ {
12
+ files: ['**/*.{ts,tsx,mts,cts}'],
13
+ extends: [js.configs.recommended, ...tseslint.configs.recommended],
14
+ },
15
+ );
package/package.json CHANGED
@@ -1,6 +1,23 @@
1
1
  {
2
2
  "name": "static-analysis-check",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Lint JavaScript and TypeScript with ESLint and find unused code with Knip.",
5
+ "type": "module",
6
+ "bin": { "static-analysis-check": "bin/cli.js" },
7
+ "files": ["bin/", "eslint.config.js"],
8
+ "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" },
9
+ "scripts": {
10
+ "check": "node bin/cli.js lint bin eslint.config.js",
11
+ "prepublishOnly": "npm run check"
12
+ },
13
+ "repository": { "type": "git", "url": "git+https://github.com/mujan5427/static-analysis-check.git" },
14
+ "keywords": ["eslint", "typescript", "knip", "static-analysis", "cli"],
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@eslint/js": "^10.0.1",
18
+ "eslint": "^10.16.0",
19
+ "knip": "^6.51.1",
20
+ "typescript": "~6.0.3",
21
+ "typescript-eslint": "^8.74.0"
22
+ }
23
+ }