Files
renovate/lib/modules/platform/scm.spec.ts
Sergei Zharinov 7df11ed734 chore(lint): add enforce-ts-extension oxlint rule (#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>
2026-04-07 15:36:16 +00:00

39 lines
1.1 KiB
TypeScript

import { git } from '~test/util.ts';
import { PLATFORM_NOT_FOUND } from '../../constants/error-messages.ts';
import type { PlatformId } from '../../constants/index.ts';
import { scm, setPlatformScmApi } from './scm.ts';
vi.unmock('./scm.ts'); //mocked from test/setup
describe('modules/platform/scm', () => {
it('no platform chosen', () => {
expect(() => scm.branchExists('branchName')).toThrow(PLATFORM_NOT_FOUND);
});
it('unknown platform', () => {
expect(() => setPlatformScmApi('unknown' as PlatformId)).toThrow(
PLATFORM_NOT_FOUND,
);
});
it.each([
'azure',
'github',
'codecommit',
'bitbucket',
'bitbucket-server',
'forgejo',
'gitea',
'github',
'gitlab',
] as PlatformId[])(
'use util/git module as default implementation for platform %s',
async (platform: PlatformId) => {
git.isBranchBehindBase.mockResolvedValueOnce(true);
setPlatformScmApi(platform);
await scm.isBranchBehindBase('abc', 'main');
expect(git.isBranchBehindBase).toHaveBeenCalledTimes(1);
},
);
});