Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update eslint deps for compatibility with new TS version #18024

Merged
merged 7 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/codesandbox-react-template/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {
Fabric,
ThemeProvider,
Checkbox,
ChoiceGroup,
Dropdown,
Expand Down Expand Up @@ -42,7 +42,7 @@ function start(): void {
}

ReactDOM.render(
<Fabric>
<ThemeProvider>
<Stack gap={8}>
<Checkbox label="Unchecked checkbox (uncontrolled)" />
<ChoiceGroup defaultSelectedKey="B" options={choicegroupOptions} label="Pick One" required />
Expand All @@ -56,7 +56,7 @@ function start(): void {
styles={dropdownStyles}
/>
</Stack>
</Fabric>,
</ThemeProvider>,
_rootDiv,
);
}
Expand Down
7 changes: 7 additions & 0 deletions apps/pr-deploy-site/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/node"],
"root": true,
"settings": {
"import/resolver": {
"typescript": {
"project": "../../tsconfig.json"
}
}
},
"overrides": [
{
// pr-deploy-site.js is run without transpiling in all browsers, which means it must use
Expand Down
2 changes: 1 addition & 1 deletion apps/pr-deploy-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"clean": "just-scripts clean",
"generate:site": "just-scripts generate:site",
"lint": "eslint --ext .js,.ts ."
"lint": "eslint --ext .js,.ts --cache ."
},
"license": "MIT",
"devDependencies": {
Expand Down
9 changes: 8 additions & 1 deletion apps/test-bundles/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/node"],
"root": true
"root": true,
"settings": {
"import/resolver": {
"typescript": {
"project": "../../tsconfig.json"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Remove unused eslint-disables",
"packageName": "@fluentui/babel-make-styles",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Update eslint config",
"packageName": "@fluentui/cra-template",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Update dependencies, remove eslint@6 from peer deps, and remove usage of process.cwd()",
"packageName": "@fluentui/eslint-plugin",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Mark old ThemeProvider as deprecated to avoid confusion",
"packageName": "@fluentui/foundation-legacy",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Update eslint-disables and rename a type param to avoid shadowing (does not affect consumers)",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Update eslint overrides in examples; replace some Fabric and Customizer usage with ThemeProvider",
"packageName": "@fluentui/react-examples",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Update demo page to use ThemeProvider not Fabric",
"packageName": "@fluentui/react-monaco-editor",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Remove unused eslint-disable",
"packageName": "@fluentui/react-positioning",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "ComponentState: fix shadowing and doc syntax for type params",
"packageName": "@fluentui/react-utilities",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Update eslint-disables in tests",
"packageName": "@fluentui/utilities",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Remove unused import",
"packageName": "@fluentui/web-components",
"email": "[email protected]",
"dependentChangeType": "none"
}
16 changes: 6 additions & 10 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// @ts-check

const { configHelpers } = require('./packages/eslint-plugin/src/index');

const eslintGlob = `*.{${configHelpers.extensions.join(',')}}`;

// https://www.npmjs.com/package/lint-staged
module.exports = {
// Run eslint in fix mode followed by prettier (must be done in sequence, separate from other
// prettier formatting, since both commands can modify files)
[eslintGlob]: ['node ./scripts/lint-staged/eslint', 'prettier --write'],

// Run prettier on non-eslintable files (ignores handled by .prettierignore)
[`!(${eslintGlob})`]: 'prettier --write',
// Run eslint in fix mode for applicable files followed by prettier.
// - The eslint wrapper handles filtering which files should be linted, since we need to both:
// - respect ignore files (which eslint doesn't do by default when passed a specific file path)
// - match the set of files that are linted by the package's normal `lint` command
// - Prettier must be run in sequence after eslint since both of them can modify files
'*': ['node ./scripts/lint-staged/eslint', 'prettier --write'],
};
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"cypress": "6.6.0",
"cypress-real-events": "1.2.0",
"danger": "^6.0.5",
"eslint": "7.25.0",
"eslint-plugin-es": "4.1.0",
"file-loader": "6.2.0",
"gulp": "^4.0.2",
Expand Down Expand Up @@ -156,7 +157,7 @@
"packages/*",
"packages/fluentui/*",
"scripts",
"tools/"
"tools"
],
"nohoist": [
"@fluentui/make-styles/@types/stylis",
Expand All @@ -178,6 +179,9 @@
"resolutions": {
"@types/react": "16.9.42",
"@types/react-dom": "16.9.10",
"@typescript-eslint/eslint-plugin": "4.22.0",
"@typescript-eslint/experimental-utils": "4.22.0",
"@typescript-eslint/parser": "4.22.0",
Comment on lines +182 to +184
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forced these resolutions because eslint-plugin-deprecation, the web-components eslint config, and maybe a couple other things still use older versions of the deps. It's not ideal but appears to be working okay at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding that deprecation plugin, this is the reason why? https://github.com/gund/eslint-plugin-deprecation/blob/master/package.json#L27

"eslint": "^7.1.0",
"//": "pretty-format contains typing only supported by TS 3.8+ remove when support in this repo is available",
"@testing-library/dom": "7.22.3",
Expand Down
2 changes: 0 additions & 2 deletions packages/babel-make-styles/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ export const plugin = declare<never, PluginObj<BabelPluginState>>(api => {
const nodePath = styleNode.nodePath;

if (styleNode.kind === 'SPREAD') {
// eslint-disable-next-line no-shadow
const evaluationResult = (nodePath.get('argument') as NodePath<t.Expression>).evaluate();

if (!evaluationResult.confident) {
Expand All @@ -450,7 +449,6 @@ export const plugin = declare<never, PluginObj<BabelPluginState>>(api => {
}

const stylesBySlots: Record<string, MakeStyles> = evaluationResult.value;
// eslint-disable-next-line no-shadow
const resolvedStyles: ResolvedStylesBySlots<string> = {};

Object.keys(stylesBySlots).forEach(slotName => {
Expand Down
9 changes: 8 additions & 1 deletion packages/cra-template/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/react"],
"root": true
"root": true,
"settings": {
"import/resolver": {
"typescript": {
"project": "../../tsconfig.json"
}
}
}
}
21 changes: 10 additions & 11 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@
},
"license": "MIT",
"scripts": {
"lint": "eslint --ext .js src"
"lint": "tsc --noEmit && eslint --ext .js --cache ."
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^3.4.0",
"@typescript-eslint/experimental-utils": "^3.4.0",
"@typescript-eslint/parser": "^3.4.0",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/experimental-utils": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-deprecation": "^1.1.0",
"eslint-plugin-import": "^2.21.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-deprecation": "^1.2.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^23.13.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^4.0.8",
"eslint-plugin-react-hooks": "^4.2.0",
"jju": "^1.4.0"
},
"devDependencies": {
"@types/eslint": "^7.2.0",
"eslint": "^7.1.0"
"@types/eslint": "7.2.10"
},
"peerDependencies": {
"eslint": "^6.0.0 || ^7.0.0",
"eslint": "^7.0.0",
"typescript": "^4.1.0"
},
"files": [
Expand Down
18 changes: 10 additions & 8 deletions packages/eslint-plugin/src/configs/react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// @ts-check
const path = require('path');
const configHelpers = require('../utils/configHelpers');

const gitRoot = configHelpers.findGitRoot();

/** @type {import("eslint").Linter.Config} */
const config = {
extends: [
Expand All @@ -20,8 +23,10 @@ const config = {
},
'import/resolver': {
typescript: {
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory
directory: process.cwd(),
// always try to resolve types under `<root>@types` directory
alwaysTryTypes: true,
// NOTE: For packages without a tsconfig.json, override with "project": "../../tsconfig.json"
project: ['./tsconfig.json', path.join(gitRoot, 'tsconfig.json')],
},
},
},
Expand Down Expand Up @@ -304,13 +309,15 @@ const getOverrides = () => [
],
},
],
'@typescript-eslint/no-shadow': 'error',

// permanently disable due to using other rules which do the same thing
camelcase: 'off', // redundant with @typescript-eslint/naming-convention

// permanently disable due to improper TS handling or unnecessary for TS
// (and not covered by plugin:@typescript-eslint/eslint-recommended)
'no-empty-function': 'off',
'no-shadow': 'off',
'no-unused-vars': 'off',
'react/jsx-filename-extension': 'off',
},
Expand Down Expand Up @@ -360,12 +367,7 @@ const getOverrides = () => [
{
files: [...configHelpers.devDependenciesFiles],
rules: {
'import/no-extraneous-dependencies': [
'error',
{
packageDir: [process.cwd(), configHelpers.findGitRoot()],
},
],
'import/no-extraneous-dependencies': ['error', { packageDir: ['.', gitRoot] }],
},
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
/** @type {*} */
// @ts-ignore
const util = require('@typescript-eslint/eslint-plugin/dist/util');
const { AST_NODE_TYPES } = require('@typescript-eslint/experimental-utils');
const createRule = require('../utils/createRule');
Expand Down
3 changes: 0 additions & 3 deletions packages/eslint-plugin/src/utils/configHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ const camelOrPascalOrUpperCase = `(${camelOrPascalCase}|${upperCase})`;
const builtins = '^(any|Number|number|String|string|Boolean|boolean|Undefined|undefined)$';

module.exports = {
/** File extensions to lint (with leading .) */
extensions: ['.ts', '.tsx', '.js', '.jsx'],

/** Test-related files */
testFiles,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"checkJs": true,
"module": "commonjs",
"moduleResolution": "node",
"noUnusedLocals": true,
"strict": true
"skipLibCheck": true,
"strict": true,
"types": ["node"]
},
"include": ["src/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const PillActionableExample = () => (
<Pill
actionable
onDismiss={(e, data) => {
// eslint-disable-next-line no-console
console.log(e, data);
}}
>
Expand Down
1 change: 1 addition & 0 deletions packages/fluentui/docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export type KnobGeneratorOptions = {
};
export type KnobDefinition = UseKnobOptions<any> & { hook: Function };

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type KnobGenerator<T> = (options: KnobGeneratorOptions) => KnobDefinition;

export type KnobComponentGenerators<P> = Partial<Record<keyof P, KnobGenerator<any>>>;
7 changes: 6 additions & 1 deletion packages/fluentui/react-bindings/src/compose/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ export type Input<TElementType extends React.ElementType = 'div', TProps = {}> =
| InputComposeComponent<TProps>
| ComposeRenderFunction<TElementType, TProps & { as?: React.ElementType }>;

export type ComposeRenderFunction<TElementType extends React.ElementType = 'div', TProps = {}, _TState = TProps> = (
export type ComposeRenderFunction<
TElementType extends React.ElementType = 'div',
TProps = {},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_TState = TProps
> = (
props: TProps,
ref: React.Ref<TElementType extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[TElementType] : TElementType>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Loading