Skip to content

Commit

Permalink
Add new TypeScript extensions (.mts, .cts) (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Aug 12, 2023
1 parent ff4b5d8 commit 04552b8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/plugins.cjs
Expand Up @@ -314,6 +314,8 @@ module.exports = {
// TypeScript doesn't yet support using extensions and fails with error TS2691.
'.ts': 'never',
'.tsx': 'never',
'.mts': 'never',
'.cts': 'never',
},
],
'n/no-mixed-requires': [
Expand Down
2 changes: 2 additions & 0 deletions lib/constants.js
Expand Up @@ -24,6 +24,8 @@ const MERGE_OPTIONS_CONCAT = [
const TYPESCRIPT_EXTENSION = [
'ts',
'tsx',
'mts',
'cts',
];

const DEFAULT_EXTENSION = [
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -315,7 +315,7 @@ Setting this to an object enables the resolver and passes the object as configur

## TypeScript

XO will automatically lint TypeScript files (`.ts`, `.d.ts` and `.tsx`) with the rules defined in [eslint-config-xo-typescript#use-with-xo](https://github.com/xojs/eslint-config-xo-typescript#use-with-xo).
XO will automatically lint TypeScript files (`.ts`, `.mts`, `.cts`, `.d.ts` and `.tsx`) with the rules defined in [eslint-config-xo-typescript#use-with-xo](https://github.com/xojs/eslint-config-xo-typescript#use-with-xo).

XO will handle the [@typescript-eslint/parser `project` option](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#parseroptionsproject) automatically even if you don't have a `tsconfig.json` in your project.

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/typescript/child/extra-semicolon.cts
@@ -0,0 +1 @@
console.log('extra-semicolon');;
1 change: 1 addition & 0 deletions test/fixtures/typescript/child/extra-semicolon.mts
@@ -0,0 +1 @@
console.log('extra-semicolon');;
18 changes: 18 additions & 0 deletions test/lint-files.js
Expand Up @@ -216,6 +216,24 @@ test.serial('typescript files', async t => {
),
);

t.true(
hasRule(
results,
path.resolve('fixtures/typescript/child/extra-semicolon.mts'),
'@typescript-eslint/no-extra-semi',
rulesMeta,
),
);

t.true(
hasRule(
results,
path.resolve('fixtures/typescript/child/extra-semicolon.cts'),
'@typescript-eslint/no-extra-semi',
rulesMeta,
),
);

t.true(
hasRule(
results,
Expand Down

0 comments on commit 04552b8

Please sign in to comment.