Skip to content

Commit b319f30

Browse files
authored
[eslint-plugin] update regex of matching TypeScript file extentions (Azure#32571)
Some of our custom rules perform operations on TypeScript files only and they use a regex of `/\.ts$/.test(fileName)` to check whether a file is TypeScript code file or not. With the migration to ESM, we can have *.mts and *.cts files as well. This PR updates the pattern to also match those files. ### Packages impacted by this PR `@azure/eslint-plugin-azure-sdk`
1 parent 60e55d8 commit b319f30

File tree

7 files changed

+44
-2
lines changed

7 files changed

+44
-2
lines changed

common/tools/eslint-plugin-azure-sdk/src/rules/github-source-headers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default createRule({
3333
},
3434
defaultOptions: [],
3535
create(context) {
36-
if (!/\.ts$/.test(context.filename)) {
36+
if (!/\.ts|\.mts|\.cts$/.test(context.filename)) {
3737
return {};
3838
}
3939
return {

common/tools/eslint-plugin-azure-sdk/src/rules/ts-doc-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default createRule({
113113
const fileName = context.filename;
114114

115115
// on the first run, if on a .ts file (program.getSourceFile is file-type dependent)
116-
if (context.settings.exported === undefined && /\.ts$/.test(fileName)) {
116+
if (context.settings.exported === undefined && /\.ts|\.mts|\.cts$/.test(fileName)) {
117117
const packageExports = getLocalExports(context);
118118
if (packageExports !== undefined) {
119119
context.settings.exported = packageExports;

common/tools/eslint-plugin-azure-sdk/tests/fixture/file-browser.mts

Whitespace-only changes.

common/tools/eslint-plugin-azure-sdk/tests/fixture/src/test-browser.mts

Whitespace-only changes.

common/tools/eslint-plugin-azure-sdk/tests/fixture/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
},
55
"include": [
66
"file.ts",
7+
"file-browser.mts",
78
"package.json",
89
"not_package.json",
910
"src/test.ts",
11+
"src/test-browser.mts",
1012
"tests/test.ts",
1113
"service-bus/package.json",
1214
"invalid/package.json",

common/tools/eslint-plugin-azure-sdk/tests/rules/github-source-headers.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ ruleTester.run("github-source-headers", rule, {
3939
code: valid,
4040
filename: "file.ts",
4141
},
42+
{
43+
// only the fields we care about
44+
code: valid,
45+
filename: "file-browser.mts",
46+
},
4247
{
4348
// incorrect format but in a file we don't care about
4449
code: 'console.log("hello")',
@@ -57,6 +62,17 @@ ruleTester.run("github-source-headers", rule, {
5762
],
5863
output: valid,
5964
},
65+
{
66+
// no comments .mts
67+
code: 'console.log("hello")',
68+
filename: "file-browser.mts",
69+
errors: [
70+
{
71+
message: configError,
72+
},
73+
],
74+
output: valid,
75+
},
6076
// wrong headers
6177
{
6278
code: invalid1,

common/tools/eslint-plugin-azure-sdk/tests/rules/ts-doc-internal.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ ruleTester.run("ts-doc-internal", rule, {
7474
function ExampleFunction() {}`,
7575
filename: "src/test.ts",
7676
},
77+
{
78+
code: `
79+
/**
80+
* Other documentation
81+
* @hidden
82+
*/
83+
function ExampleFunction() {}`,
84+
filename: "src/test-browser.mts",
85+
},
7786
],
7887
invalid: [
7988
// class
@@ -119,5 +128,20 @@ ruleTester.run("ts-doc-internal", rule, {
119128
},
120129
],
121130
},
131+
// .mts file
132+
{
133+
code: `
134+
/**
135+
* Other documentation
136+
* @ignore
137+
*/
138+
function ExampleFunction() {}`,
139+
filename: "src/test-browser.mts",
140+
errors: [
141+
{
142+
message: "internal items with TSDoc comments should include an @internal or @hidden tag",
143+
},
144+
],
145+
},
122146
],
123147
});

0 commit comments

Comments
 (0)