Skip to content

Commit

Permalink
[core] Continue eslint sync with main repo (#2004)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Jul 28, 2020
1 parent e33282a commit 537dc6e
Show file tree
Hide file tree
Showing 142 changed files with 1,658 additions and 1,345 deletions.
214 changes: 184 additions & 30 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,197 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
root: true, // So parent files don't get applied
globals: {
preval: false, // Used in the documentation
},
settings: {
react: {
version: 'detect',
},
env: {
es6: true,
browser: true,
node: true,
jest: true,
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'airbnb-typescript',
'prettier',
'prettier/react',
'prettier/@typescript-eslint',
],
plugins: ['react', 'react-hooks', 'pretty-imports', '@typescript-eslint'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 7,
},
plugins: ['react-hooks', '@typescript-eslint'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
},
},
},
/**
* Sorted alphanumerically within each group. built-in and each plugin form
* their own groups.
*/
rules: {
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/no-explicit-any': 0,
// in scripts and config files it's required to use dynamic require
'@typescript-eslint/no-var-requires': 0,
'react/no-children-prop': 0,
'react/jsx-uses-vars': 2,
'react/jsx-uses-react': 2,
'pretty-imports/sorted': 'warn',
'@typescript-eslint/no-use-before-define': 'warn',
'consistent-this': ['error', 'self'],
// just as bad as "max components per file"
'max-classes-per-file': 'off',
'no-alert': 'error', // Too much interruptive
'no-console': ['error', { allow: ['warn', 'error'] }], // Allow warn and error for production events
'no-param-reassign': 'off', // It's fine.
'no-constant-condition': 'error',
'no-prototype-builtins': 'off', // Use the proptype inheritance chain
'no-underscore-dangle': 'error',
'nonblock-statement-body-position': 'error',
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
'prefer-destructuring': 'off', // Destructuring harm grep potential.
'@typescript-eslint/dot-notation': 'off', // TODO performance consideration
'@typescript-eslint/no-implied-eval': 'off', // TODO performance consideration
'@typescript-eslint/no-throw-literal': 'off', // TODO performance consideration
'import/named': 'off', // Not sure why it doesn't work
'import/no-extraneous-dependencies': 'off', // Missing yarn workspace support
'jsx-a11y/label-has-associated-control': 'off', // doesn't work?
'jsx-a11y/no-autofocus': 'off', // We are a library, we need to support it too
'react-hooks/exhaustive-deps': ['error', { additionalHooks: 'useEnhancedEffect' }],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'after-used', argsIgnorePattern: '^_', ignoreRestSiblings: true },
'react/destructuring-assignment': 'off', // It's fine.
'react/forbid-prop-types': 'off', // Too strict, no time for that
'react/jsx-curly-brace-presence': 'off', // broken
'react/jsx-filename-extension': ['error', { extensions: ['.js', '.tsx'] }], // airbnb is using .jsx
'react/jsx-fragments': ['error', 'element'], // Prefer <React.Fragment> over <>.
'react/jsx-props-no-spreading': 'off', // We are a UI library.
'react/no-array-index-key': 'off', // This rule is great for raising people awareness of what a key is and how it works.
'react/no-danger': 'error',
'react/no-direct-mutation-state': 'error',
'react/no-find-dom-node': 'off', // Required for backward compatibility. TODO v5, drop
'react/require-default-props': 'off', // Not always relevant
'react/sort-prop-types': 'error',
// This depends entirely on what you're doing. There's no universal pattern
'react/state-in-constructor': 'off',
// stylistic opinion. For conditional assignment we want it outside, otherwise as static
'react/static-property-placement': 'off',

// TODO
'import/no-cycle': 'warn',
'import/prefer-default-export': 'off',
'jsx-a11y/click-events-have-key-events': 'warn',
'jsx-a11y/control-has-associated-label': 'warn',
'jsx-a11y/no-static-element-interactions': 'warn',
'no-nested-ternary': 'warn',
'no-shadow': 'warn',
'react/prop-types': 'off', // For public API
'no-restricted-imports': [
'warn',
{
patterns: [
'@material-ui/*/*/*',
'!@material-ui/core/test-utils/*',
'!@material-ui/utils/macros/*.macro',
],
},
],
},
overrides: [
{
files: [
'**/test-utils/**/*.js',
// matching the pattern of the test runner
'*.test.js',
],
env: {
mocha: true,
},
extends: ['plugin:mocha/recommended'],
rules: {
// does not work with wildcard imports. Mistakes will throw at runtime anyway
'import/named': 'off',
'no-restricted-imports': [
'error',
{
paths: [
{
name: '@material-ui/core/test-utils',
importNames: ['createMount'],
message:
"Please use `import createMount from 'test/utils/createMount'` instead. `createMount` from /core has cleanup issues that require breaking changes.",
},
],
},
],

// upgraded level from recommended
'mocha/no-exclusive-tests': 'error',
'mocha/no-skipped-tests': 'error',

// no rationale provided in /recommended
'mocha/no-mocha-arrows': 'off',
// definitely a useful rule but too many false positives
// due to `describeConformance`
// "If you're using dynamically generated tests, you should disable this rule.""
'mocha/no-setup-in-describe': 'off',
// `beforeEach` for a single case is optimized for change
// when we add a test we don't have to refactor the existing
// test to `beforeEach`.
// `beforeEach`+`afterEach` also means that the `beforeEach`
// is cleaned up in `afterEach` if the test causes a crash
'mocha/no-hooks-for-single-case': 'off',

// disable eslint-plugin-jsx-a11y
// tests are not driven by assistive technology
// add `jsx-a11y` rules once you encounter them in tests
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/control-has-associated-label': 'off',
'jsx-a11y/iframe-has-title': 'off',
'jsx-a11y/mouse-events-have-key-events': 'off',
'jsx-a11y/no-noninteractive-tabindex': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'jsx-a11y/tabindex-no-positive': 'off',

// They are accessed to test custom validator implementation with PropTypes.checkPropTypes
'react/forbid-foreign-prop-types': 'off',
// components that are defined in test are isolated enough
// that they don't need type-checking
'react/prop-types': 'off',
},
},
{
files: ['docs/pages/**/*.js'],
rules: {
'react/prop-types': 'off',
},
},
{
files: ['*.d.ts'],
rules: {
'import/export': 'off', // Not sure why it doesn't work
},
},
{
files: ['*.spec.tsx', '*.spec.ts'],
rules: {
'no-alert': 'off',
'no-console': 'off',
'no-empty-pattern': 'off',
'no-lone-blocks': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'import/export': 'off', // Not sure why it doesn't work
'import/prefer-default-export': 'off',
'jsx-a11y/anchor-has-content': 'off',
'jsx-a11y/anchor-is-valid': 'off',
'jsx-a11y/tabindex-no-positive': 'off',
'react/default-props-match-prop-types': 'off',
'react/no-access-state-in-setstate': 'off',
'react/no-unused-prop-types': 'off',
'react/prefer-stateless-function': 'off',
'react/prop-types': 'off',
'react/require-default-props': 'off',
'react/state-in-constructor': 'off',
'react/static-property-placement': 'off',
},
},
],
};
6 changes: 3 additions & 3 deletions docs/_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ export const CODESANDBOX_EXAMPLE_ID = 'material-ui-pickers-v4-jfm6g';

export const DOMAIN = 'material-ui-pickers.dev';

export const HOST_URL = 'https://' + DOMAIN;
export const HOST_URL = `https://${DOMAIN}`;

export const LOGO_URL = HOST_URL + '/static/meta-image.png';
export const LOGO_URL = `${HOST_URL}/static/meta-image.png`;

export const GITHUB_URL = 'https://github.com/mui-org/material-ui-pickers';

export const GITHUB_EDIT_URL = GITHUB_URL + '/edit/next/docs/';
export const GITHUB_EDIT_URL = `${GITHUB_URL}/edit/next/docs/`;
9 changes: 2 additions & 7 deletions docs/_shared/Example.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from 'react';
import clsx from 'clsx';
import Code from './Code';
import CodeIcon from '@material-ui/icons/Code';
import CopyIcon from '@material-ui/icons/FileCopy';
import { makeStyles, IconButton, Collapse, Tooltip } from '@material-ui/core';
import GithubIcon from '_shared/svgIcons/GithubIcon';
import { copy } from 'utils/helpers';
import { useSnackbar } from 'notistack';
import { GITHUB_EDIT_URL } from '_constants';
import { replaceGetFormatStrings } from 'utils/utilsService';
import Code from './Code';
import { withUtilsService, UtilsContext } from './UtilsServiceContext';
import { makeStyles, IconButton, Collapse, Tooltip } from '@material-ui/core';

interface ExampleProps {
testId: string;
Expand Down Expand Up @@ -107,23 +107,19 @@ function Example({ source, testId, paddingBottom }: ExampleProps) {
</IconButton>
</a>
</Tooltip>

<Tooltip title="Copy source">
<IconButton onClick={copySource}>
<CopyIcon />
</IconButton>
</Tooltip>

<IconButton className={classes.toolbarSourceBtn} onClick={() => setExpanded(!expanded)}>
<CodeIcon />
</IconButton>
</div>

<div className={classes.codeContainer}>
{replacedSource && <Code children={replacedSource} />}
</div>
</Collapse>

<div
data-mui-test={testId}
className={clsx(classes.pickers, { [classes.paddingBottom]: paddingBottom })}
Expand All @@ -133,7 +129,6 @@ function Example({ source, testId, paddingBottom }: ExampleProps) {
<CodeIcon />
</IconButton>
</Tooltip>

<ExampleComponent key={currentLib} />
</div>
</React.Fragment>
Expand Down
2 changes: 0 additions & 2 deletions docs/_shared/PageMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ export function PageMeta({ title, component, router, description }: PageMetaProp
return (
<Head>
<title>{title}</title>

<meta name="twitter:card" content="summary" />
<meta name="twitter:image" content={LOGO_URL} />
<meta name="description" content={description} />
<meta name="og:description" content={description} />
<meta name="twitter:description" content={description} />

<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={LOGO_URL} />
Expand Down
17 changes: 6 additions & 11 deletions docs/_shared/PropTypesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as React from 'react';
import clsx from 'clsx';
import Code from './Code';
import FuzzySearch from 'fuzzy-search';
import ReactMarkdown from 'react-markdown';
import PropTypesDoc from '../prop-types.json';
import SearchBar from 'material-ui-search-bar';
import React, { useMemo, useState } from 'react';
import {
Table,
Paper,
Expand All @@ -16,6 +14,8 @@ import {
Typography,
Grid,
} from '@material-ui/core';
import PropTypesDoc from '../prop-types.json';
import Code from './Code';

const useStyles = makeStyles((theme) => ({
header: {
Expand Down Expand Up @@ -60,7 +60,7 @@ interface PropTypesTableProps {

const PropTypesTableLazy: React.FC<PropTypesTableProps> = ({ disableHeader, src }) => {
const classes = useStyles();
const [searchString, setSearchString] = useState('');
const [searchString, setSearchString] = React.useState('');
const propsDoc = Object.values(PropTypesDoc[src]).sort((a, b) => {
if (a.required && !b.required) {
return -1;
Expand All @@ -73,7 +73,7 @@ const PropTypesTableLazy: React.FC<PropTypesTableProps> = ({ disableHeader, src
return a.name.localeCompare(b.name);
});

const searcher = useMemo(
const searcher = React.useMemo(
() =>
new FuzzySearch(propsDoc, ['name', 'defaultValue', 'description', 'type.name'], {
sort: true,
Expand All @@ -82,7 +82,7 @@ const PropTypesTableLazy: React.FC<PropTypesTableProps> = ({ disableHeader, src
[propsDoc]
);

const propsToShow = useMemo(() => {
const propsToShow = React.useMemo(() => {
return searcher.search(searchString.trim());
}, [searchString, searcher]);

Expand All @@ -104,7 +104,6 @@ const PropTypesTableLazy: React.FC<PropTypesTableProps> = ({ disableHeader, src
</Grid>
</Grid>
)}

<Paper className={classes.tableWrapper}>
<Table>
<TableHead>
Expand All @@ -115,7 +114,6 @@ const PropTypesTableLazy: React.FC<PropTypesTableProps> = ({ disableHeader, src
<TableCell> Description </TableCell>
</TableRow>
</TableHead>

<TableBody>
{propsToShow.map((prop) => (
<TableRow key={prop.name}>
Expand All @@ -128,19 +126,16 @@ const PropTypesTableLazy: React.FC<PropTypesTableProps> = ({ disableHeader, src
{prop.required ? `${prop.name} *` : prop.name}{' '}
</Typography>
</TableCell>

<TableCell>
<Code inline language="typescript">
{prop.type.name}
</Code>
</TableCell>

<TableCell className={classes.defaultValue}>
<Typography align="center" variant="body1" component="span">
{prop.defaultValue && prop.defaultValue.value}
</Typography>
</TableCell>

<TableCell className={classes.description}>
<ReactMarkdown source={prop.description} />
</TableCell>
Expand Down
Loading

1 comment on commit 537dc6e

@vercel
Copy link

@vercel vercel bot commented on 537dc6e Jul 28, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.