Skip to content

Commit 8a349aa

Browse files
authored
Merge pull request #142 from microsoft/users/rbitting/ts-eslint-config
Set up eslint configuration for TypeScript files
2 parents 0067213 + 0876a63 commit 8a349aa

File tree

7 files changed

+33
-3
lines changed

7 files changed

+33
-3
lines changed

.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ module.exports = {
2525
{
2626
files: ["tests/**/*.js"],
2727
env: { mocha: true }
28+
},
29+
{
30+
files: ["tests/**/*.ts"],
31+
env: { jest: true }
32+
},
33+
{
34+
files: ["**/*.ts"],
35+
parser: "@typescript-eslint/parser",
36+
plugins: ["@typescript-eslint"],
37+
parserOptions: {
38+
ecmaVersion: 2021,
39+
sourceType: "module",
40+
project: "./tsconfig.json"
41+
},
42+
rules: {
43+
// Disable Node.js rules that conflict with TypeScript
44+
"node/no-missing-import": "off",
45+
"node/no-unsupported-features/es-syntax": "off",
46+
"node/no-extraneous-import": "off"
47+
}
2848
}
2949
],
3050
rules: {

lib/applicableComponents/labelBasedComponents.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
14
const labelBasedComponents = ["Label", "label"];
25
const elementsUsedAsLabels = ["div", "span", "p", "h1", "h2", "h3", "h4", "h5", "h6"];
36

lib/rules/field-needs-labelling.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"use strict";
55

6-
const { hasNonEmptyProp } = require("../util/hasNonEmptyProp");
6+
import { hasNonEmptyProp } from "../util/hasNonEmptyProp";
77
const elementType = require("jsx-ast-utils").elementType;
88
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
99

lib/rules/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
14
export { default as accordionHeaderNeedsLabelling } from "./accordion-header-needs-labelling";
25
export { default as accordionItemNeedsHeaderAndPanel } from "./accordion-item-needs-header-and-panel";
36
export { default as avatarNeedsName } from "./avatar-needs-name";

tests/lib/rules/utils/hasFieldParent.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ const createMockContext = (ancestors: TSESTree.Node[]): TSESLint.RuleContext<str
2525
report: jest.fn(),
2626
getAncestors: () => ancestors,
2727
getSourceCode: jest.fn(),
28+
// eslint-disable-next-line no-unused-vars
2829
getDeclaredVariables: function (node: TSESTree.Node): readonly TSESLint.Scope.Variable[] {
2930
throw new Error("Function not implemented.");
3031
},
32+
// eslint-disable-next-line no-unused-vars
3133
markVariableAsUsed: function (name: string): boolean {
3234
throw new Error("Function not implemented.");
3335
}

tests/lib/rules/utils/hasLabelledChilImage.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Import necessary dependencies and mock functions
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
24
import {
35
hasLabelledChildImage,
46
isImageHidden,

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
"rootDir": ".",
2020
"allowJs": true
2121
},
22-
"include": ["lib"],
22+
"include": ["lib", "tests/lib"],
2323
"exclude": ["node_modules", "dist"]
2424
}

0 commit comments

Comments
 (0)