Skip to content

Commit 7df11ed

Browse files
chore(lint): add enforce-ts-extension oxlint rule (renovatebot#42389)
* refactor(lint): extract custom oxlint rules into separate files Split `tools/lint/rules.js` into one file per rule under `tools/lint/rules/`. Also simplify `test-root-describe` with early-exit guard clauses. * feat(lint): add `enforce-ts-extension` oxlint rule Add a custom JS-based oxlint rule that enforces `.ts` extensions on local imports. The rule catches two problems: - `.js` extension used instead of `.ts` (auto-fixable) - missing file extension entirely (report only) Checked locations: - static import/export declarations - dynamic `import()` expressions - vitest module APIs: `vi.mock`, `vi.doMock`, `vi.unmock`, `vi.doUnmock`, `vi.importActual`, `vi.importMock` Both relative paths (`./`, `../`) and path aliases (`~test/`) are treated as local. Package imports are ignored. Also fixes 26 pre-existing violations across 18 spec files. * Update tools/lint/rules/enforce-ts-extension.js Co-authored-by: Anne Stellingwerf <1637358+astellingwerf@users.noreply.github.com> --------- Co-authored-by: Anne Stellingwerf <1637358+astellingwerf@users.noreply.github.com>
1 parent 47807ea commit 7df11ed

File tree

21 files changed

+165
-30
lines changed

21 files changed

+165
-30
lines changed

.oxlintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
],
4848
"no-unassigned-vars": "error",
4949

50+
"renovate/enforce-ts-extension": "error",
5051
"renovate/no-tools-import": "error",
5152

5253
"typescript/await-thenable": "error",
@@ -193,7 +194,8 @@
193194
"files": ["**/*.js", "**/*.mjs", "**/*.cjs"],
194195
"rules": {
195196
"typescript/restrict-template-expressions": "off",
196-
"typescript/explicit-function-return-type": "off"
197+
"typescript/explicit-function-return-type": "off",
198+
"renovate/enforce-ts-extension": "off"
197199
}
198200
}
199201
],

lib/config/options/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as manager from '../../modules/manager/index.ts';
33
import * as platform from '../../modules/platform/index.ts';
44
import { getOptions } from './index.ts';
55

6-
vi.unmock('../../modules/platform');
6+
vi.unmock('../../modules/platform/index.ts');
77

88
describe('config/options/index', () => {
99
it('test manager should have no defaultConfig', () => {

lib/logger/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type { RenovateLogger } from './renovate-logger.ts';
2626

2727
const logContext = 'initial_context';
2828

29-
vi.unmock('.');
29+
vi.unmock('./index.ts');
3030
vi.mock('node:crypto', () => ({
3131
randomUUID: vi.fn(() => 'initial_context'),
3232
}));

lib/logger/once.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { init, logger } from './index.ts';
22
import { once, reset } from './once.ts';
33

4-
vi.unmock('.');
4+
vi.unmock('./index.ts');
55

66
// init logger
77
await init();

lib/modules/datasource/crate/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { getPkgReleases } from '../index.ts';
1818
import { CrateDatasource } from './index.ts';
1919
import type { RegistryConfigSchema } from './schema.ts';
2020

21-
vi.unmock('../../../util/mutex');
21+
vi.unmock('../../../util/mutex.ts');
2222
vi.mock('simple-git');
2323
const simpleGit = vi.mocked(_simpleGit);
2424

lib/modules/datasource/deb/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
getRegistryUrl,
2020
} from './url.ts';
2121

22-
vi.unmock('../../../util/mutex');
22+
vi.unmock('../../../util/mutex.ts');
2323

2424
const debBaseUrl = 'http://deb.debian.org';
2525

lib/modules/manager/nuget/artifacts.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ const config: UpdateArtifactsConfig = {};
3232

3333
describe('modules/manager/nuget/artifacts', () => {
3434
beforeEach(async () => {
35-
const realFs =
36-
await vi.importActual<typeof import('../../../util/fs/index.ts')>(
37-
'../../../util/fs',
38-
);
35+
const realFs = await vi.importActual<
36+
typeof import('../../../util/fs/index.ts')
37+
>('../../../util/fs/index.ts');
3938
hostRules.find.mockReturnValue({});
4039
getDefaultRegistries.mockReturnValue([
4140
{ url: nugetOrg, name: 'nuget.org' },

lib/modules/platform/azure/azure-helper.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('modules/platform/azure/azure-helper', () => {
1616
// reset module
1717
vi.resetModules();
1818
azureHelper = await vi.importActual('./azure-helper.ts');
19-
azureApi = await vi.importMock('./azure-got-wrapper');
19+
azureApi = await vi.importMock('./azure-got-wrapper.ts');
2020
});
2121

2222
describe('getRef', () => {

lib/modules/platform/bitbucket-server/utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
getRepoGitUrl,
1414
} from './utils.ts';
1515

16-
vi.unmock('../../../util/git');
16+
vi.unmock('../../../util/git/index.ts');
1717

1818
function sshLink(projectKey: string, repositorySlug: string): string {
1919
return `ssh://git@stash.renovatebot.com:7999/${projectKey.toLowerCase()}/${repositorySlug}.git`;

lib/modules/platform/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import api from './api.ts';
66
import * as platform from './index.ts';
77
import type { Platform } from './types.ts';
88

9-
vi.unmock('.');
10-
vi.unmock('./scm');
9+
vi.unmock('./index.ts');
10+
vi.unmock('./scm.ts');
1111

1212
describe('modules/platform/index', () => {
1313
beforeEach(() => {

0 commit comments

Comments
 (0)