|
1 | 1 | import { describe, it, expect, beforeEach, afterEach } from 'vitest'; |
2 | 2 | import { createFixture } from '../test-utils/index.ts'; |
3 | | -import { runOxlint, runKnip } from './lint.ts'; |
| 3 | +import { runOxlint, runKnip, runKnipFix } from './lint.ts'; |
4 | 4 | import { fileURLToPath } from 'node:url'; |
5 | 5 |
|
6 | 6 | describe('lint command', () => { |
@@ -83,6 +83,21 @@ describe('lint command', () => { |
83 | 83 | [], |
84 | 84 | ); |
85 | 85 | }); |
| 86 | + |
| 87 | + it('auto-fixes console.log to console.info', async () => { |
| 88 | + fixture = await createFixture({ |
| 89 | + src: { |
| 90 | + 'index.ts': 'console.log("hello");\nconsole.info("ok");\n', |
| 91 | + }, |
| 92 | + }); |
| 93 | + process.chdir(fileURLToPath(fixture.root)); |
| 94 | + |
| 95 | + await runOxlint(['./src'], true); |
| 96 | + |
| 97 | + expect(await fixture.text('src/index.ts')).toBe( |
| 98 | + 'console.info("hello");\nconsole.info("ok");\n', |
| 99 | + ); |
| 100 | + }); |
86 | 101 | }); |
87 | 102 |
|
88 | 103 | describe('bombshell-dev/max-params', () => { |
@@ -117,7 +132,34 @@ describe('lint command', () => { |
117 | 132 | const violations = await runOxlint(['./src']); |
118 | 133 | const maxParams = violations.filter((v) => v.code === 'bombshell-dev(max-params)'); |
119 | 134 |
|
120 | | - expect(maxParams.map((v) => v.line).sort((a, b) => a - b)).toEqual([2, 3, 4, 11]); |
| 135 | + expect(maxParams.map((v) => v.line!).sort((a, b) => a - b)).toEqual([2, 3, 4, 11]); |
| 136 | + }); |
| 137 | + }); |
| 138 | + |
| 139 | + describe('runKnipFix', () => { |
| 140 | + it('removes unused dependencies from package.json', async () => { |
| 141 | + fixture = await createFixture({ |
| 142 | + 'package.json': { |
| 143 | + name: 'test-pkg', |
| 144 | + version: '1.0.0', |
| 145 | + type: 'module', |
| 146 | + exports: './src/index.ts', |
| 147 | + dependencies: { 'left-pad': '^1.3.0' }, |
| 148 | + }, |
| 149 | + src: { |
| 150 | + 'index.ts': 'export const value = 42;\n', |
| 151 | + }, |
| 152 | + }); |
| 153 | + process.chdir(fileURLToPath(fixture.root)); |
| 154 | + |
| 155 | + const before = await runKnip(); |
| 156 | + expect(before.some((v) => v.code === 'unused-dependency')).toBe(true); |
| 157 | + |
| 158 | + await runKnipFix(); |
| 159 | + |
| 160 | + const pkg = (await fixture.json('package.json')) as { dependencies?: unknown }; |
| 161 | + expect(pkg.dependencies ?? {}).toEqual({}); |
| 162 | + expect(await runKnip()).toEqual([]); |
121 | 163 | }); |
122 | 164 | }); |
123 | 165 |
|
|
0 commit comments