Skip to content

Commit f0fb922

Browse files
authored
[eslint-plugin] skip some package json linting for packages using tshy (#29912)
as packages using tshy has been migrated to ESM and these rules no longer apply to them. This PR skip these rules to avoid having to turn them off for individual packages. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? We could remove these rules too. Although it's still nice to have them before we migrage all packages to ESM with tshy.
1 parent 0f92b9e commit f0fb922

20 files changed

Lines changed: 48 additions & 74 deletions

File tree

common/tools/dev-tool/src/commands/admin/list/esm-migrations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function createMigrationResult(): MigrationResult {
8888
}
8989

9090
function setMigrationResult(
91+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9192
packageJson: any,
9293
project: RushJsonProject,
9394
results: MigrationResult,

common/tools/eslint-plugin-azure-sdk/src/rules/ts-apiextractor-json-types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @file Rule to force the inclusion of type declarations in the package.
66
*/
77

8-
import { createRule, getVerifiers, stripPath } from "../utils";
8+
import { createRule, getVerifiers, stripPath, usesTshy } from "../utils";
99
import { TSESTree } from "@typescript-eslint/utils";
1010
import { VerifierMessages, stripFileName } from "../utils/verifiers";
1111

@@ -42,6 +42,9 @@ export default createRule({
4242
if (stripPath(fileName) !== "api-extractor.json") {
4343
return {};
4444
}
45+
if (usesTshy(context.filename)) {
46+
return {};
47+
}
4548
return {
4649
// callback functions
4750
"ExpressionStatement > ObjectExpression": verifiers.existsInFile,

common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-files-required.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
*
77
*/
88
import { TSESTree } from "@typescript-eslint/utils";
9-
import { VerifierMessages, arrayToString, createRule, getVerifiers, stripPath } from "../utils";
9+
import {
10+
VerifierMessages,
11+
arrayToString,
12+
createRule,
13+
getVerifiers,
14+
stripPath,
15+
usesTshy,
16+
} from "../utils";
1017

1118
//------------------------------------------------------------------------------
1219
// Rule Definition
@@ -75,6 +82,9 @@ export default createRule({
7582
if (stripPath(context.filename) !== "package.json") {
7683
return {};
7784
}
85+
if (usesTshy(context.filename)) {
86+
return {};
87+
}
7888
return {
7989
// check to see if files exists at the outermost level
8090
"ExpressionStatement > ObjectExpression": verifiers.existsInFile,

common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-main-is-cjs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { TSESTree } from "@typescript-eslint/utils";
10-
import { VerifierMessages, createRule, getVerifiers, stripPath } from "../utils";
10+
import { VerifierMessages, createRule, getVerifiers, stripPath, usesTshy } from "../utils";
1111

1212
//------------------------------------------------------------------------------
1313
// Rule Definition
@@ -38,6 +38,9 @@ export default createRule({
3838
if (stripPath(context.filename) !== "package.json") {
3939
return {};
4040
}
41+
if (usesTshy(context.filename)) {
42+
return {};
43+
}
4144
return {
4245
// check to see if main exists at the outermost level
4346
"ExpressionStatement > ObjectExpression": verifiers.existsInFile,

common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { TSESTree } from "@typescript-eslint/utils";
10-
import { VerifierMessages, createRule, getVerifiers, stripPath } from "../utils";
10+
import { VerifierMessages, createRule, getVerifiers, stripPath, usesTshy } from "../utils";
1111

1212
//------------------------------------------------------------------------------
1313
// Rule Definition
@@ -38,6 +38,9 @@ export default createRule({
3838
if (stripPath(context.filename) !== "package.json") {
3939
return {};
4040
}
41+
if (usesTshy(context.filename)) {
42+
return {};
43+
}
4144
return {
4245
// check to see if module exists at the outermost level
4346
"ExpressionStatement > ObjectExpression": verifiers.existsInFile,

common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { TSESTree } from "@typescript-eslint/utils";
10-
import { createRule, getVerifiers, stripPath } from "../utils";
10+
import { createRule, getVerifiers, stripPath, usesTshy } from "../utils";
1111
import { VerifierMessages, stripFileName } from "../utils/verifiers";
1212

1313
//------------------------------------------------------------------------------
@@ -42,6 +42,9 @@ export default createRule({
4242
if (stripPath(context.filename) !== "package.json") {
4343
return {};
4444
}
45+
if (usesTshy(context.filename)) {
46+
return {};
47+
}
4548
return {
4649
// check to see if types exists at the outermost level
4750
"ExpressionStatement > ObjectExpression": verifiers.existsInFile,

common/tools/eslint-plugin-azure-sdk/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {
1111
arrayToString,
1212
getVerifiers,
1313
stripPath,
14+
usesTshy,
1415
VerifierMessages,
1516
type VerifierMessageIds,
1617
} from "./verifiers";

common/tools/eslint-plugin-azure-sdk/src/utils/verifiers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77

88
import { TSESTree, TSESLint } from "@typescript-eslint/utils";
9+
import { statSync } from "node:fs";
10+
import * as path from "node:path";
911

1012
interface StructureData {
1113
outer: string;
@@ -42,6 +44,15 @@ export type VerifierMessageIds = keyof typeof VerifierMessages;
4244
export const stripPath = (pathOrFileName: string): string =>
4345
pathOrFileName.replace(/^.*[\\\/]/, "");
4446

47+
export function usesTshy(packageJsonPath: string): boolean {
48+
const dotTshy = path.join(path.dirname(packageJsonPath), ".tshy");
49+
try {
50+
statSync(dotTshy);
51+
return true;
52+
} catch {
53+
return false;
54+
}
55+
}
4556
/**
4657
* Get the directory of a filename
4758
* @param pathOrFileName the input path or file name

sdk/.eslintrc.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
22
"plugins": ["@azure/azure-sdk"],
33
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
4-
"ignorePatterns": ["**/test/perf/track-1"],
5-
"rules": {
6-
"@azure/azure-sdk/ts-package-json-module": "off",
7-
"@azure/azure-sdk/ts-package-json-files-required": "off",
8-
"@azure/azure-sdk/ts-package-json-main-is-cjs": "off",
9-
"@azure/azure-sdk/ts-package-json-types": "off"}
4+
"ignorePatterns": ["**/test/perf/track-1"]
105
}

sdk/apimanagement/api-management-custom-widgets-scaffolder/.eslintrc.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
{
22
"plugins": ["@azure/azure-sdk"],
33
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
4-
"rules": {
5-
"@azure/azure-sdk/ts-package-json-types": "off",
6-
"@azure/azure-sdk/ts-package-json-main-is-cjs": "off",
7-
"@azure/azure-sdk/ts-package-json-module": "off"
8-
},
94
"ignorePatterns": [],
105
"overrides": [
116
{

0 commit comments

Comments
 (0)