Skip to content

Commit

Permalink
Switch from TSLint to ESLint (#2604)
Browse files Browse the repository at this point in the history
Related issues: #2054

Motivation:

TSLint is officially announced to be deprecated in 2019.

Modifications:

- Replace TSLint with ESLint
- Fix some linting errors
- Place `eslintrc.js` and `prettierrc.js` under `settings/` so that
  other frontend modules (e.g. Gatsby) can use it as well.

Result:

- New and shiny linting
  • Loading branch information
trustin authored Mar 19, 2020
1 parent f9e1365 commit 7f89c81
Show file tree
Hide file tree
Showing 26 changed files with 1,505 additions and 549 deletions.
6 changes: 6 additions & 0 deletions docs-client/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const defaultConfig = require('../settings/eslint/eslintrc');

module.exports = {
...defaultConfig,
ignorePatterns: [...defaultConfig.ignorePatterns, 'webpack.config.ts'],
};
5 changes: 5 additions & 0 deletions docs-client/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const defaultConfig = require('../settings/prettier/prettierrc');

module.exports = {
...defaultConfig,
};
30 changes: 21 additions & 9 deletions docs-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"scripts": {
"prebuild": "yarn run check",
"build": "cross-env TS_NODE_PROJECT=\"tsconfig-webpack.json\" webpack",
"check": "tsc --project . && tslint --project .",
"start": "cross-env TS_NODE_PROJECT=\"tsconfig-webpack.json\" WEBPACK_DEV=true webpack-dev-server"
"check": "tsc --project . && yarn run lint",
"start": "cross-env TS_NODE_PROJECT=\"tsconfig-webpack.json\" WEBPACK_DEV=true webpack-dev-server",
"lint": "eslint --ext .json,.js,.jsx,.ts,.tsx .",
"lint:fix": "eslint --fix --ext .json,.js,.jsx,.ts,.tsx ."
},
"dependencies": {
"@material-ui/core": "^4.3.1",
Expand All @@ -19,9 +21,11 @@
"react-dropdown": "^1.6.2",
"react-helmet": "^5.2.0",
"react-hot-loader": "^4.12.10",
"react-router": "^5.1.2",
"react-router-dom": "^5.0.1",
"react-select": "^3.0.4",
"react-syntax-highlighter": "^11.0.2"
"react-syntax-highlighter": "^11.0.2",
"regenerator-runtime": "^0.13.5"
},
"devDependencies": {
"@babel/core": "^7.1.0",
Expand All @@ -40,22 +44,30 @@
"@types/react-syntax-highlighter": "^10.2.1",
"@types/webpack": "^4.4.17",
"@types/webpack-dev-server": "^3.1.7",
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
"babel-loader": "^8.0.4",
"cross-env": "^5.2.0",
"css-loader": "^3.2.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-config-airbnb-typescript": "^7.2.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-json": "^2.1.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^2.5.0",
"favicons-webpack-plugin": "^2.0.0",
"file-loader": "^4.1.0",
"html-webpack-plugin": "^3.2.0",
"prettier": "^1.14.3",
"prettier": "^1.19.1",
"style-loader": "^1.0.0",
"ts-loader": "^6.0.4",
"ts-node": "^8.3.0",
"tsconfig-paths": "^3.6.0",
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-plugin-prettier": "^2.0.1",
"tslint-react": "^4.0.0",
"typescript": "^3.2.2",
"webpack": "^4.39.1",
"webpack-cli": "^3.1.2",
Expand Down
16 changes: 8 additions & 8 deletions docs-client/src/components/GotoSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function SingleValue(props: SingleValueProps<OptionType>) {
return (
<Typography
className={props.selectProps.classes.singleValue}
noWrap={true}
noWrap
{...props.innerProps}
>
{props.children}
Expand Down Expand Up @@ -288,9 +288,9 @@ function makeSuggestions(
if (specification.getServices().length > 0 && remain > 0) {
suggestions.push({
label: 'Services',
options: specification.getServices().flatMap((service) => {
options: specification.getServices().flatMap(service => {
return service.methods
.map((method) => {
.map(method => {
return {
label: `${service.name}#${method.name}|${method.httpMethod}`,
value: `/methods/${service.name}/${method.name}/${method.httpMethod}`,
Expand All @@ -306,7 +306,7 @@ function makeSuggestions(
label: 'Enums',
options: specification
.getEnums()
.map((enm) => {
.map(enm => {
return {
label: `${enm.name}`,
value: `/enums/${enm.name}/`,
Expand All @@ -321,7 +321,7 @@ function makeSuggestions(
label: 'Structs',
options: specification
.getStructs()
.map((struct) => {
.map(struct => {
return {
label: `${struct.name}`,
value: `/structs/${struct.name}/`,
Expand All @@ -336,7 +336,7 @@ function makeSuggestions(
label: 'Exceptions',
options: specification
.getExceptions()
.map((exception) => {
.map(exception => {
return {
label: `${exception.name}`,
value: `/structs/${exception.name}/`,
Expand Down Expand Up @@ -389,7 +389,7 @@ const GotoSelect: React.FunctionComponent<GotoSelectProps> = ({
const filterSuggestion = useCallback(
(inputValue: string, callback: (n: GroupType[]) => void): void => {
callback(
makeSuggestions(specification, FILTERED_SUGGESTION_SIZE, (suggestion) =>
makeSuggestions(specification, FILTERED_SUGGESTION_SIZE, suggestion =>
suggestion.toLowerCase().includes(inputValue.toLowerCase()),
),
);
Expand All @@ -403,7 +403,7 @@ const GotoSelect: React.FunctionComponent<GotoSelectProps> = ({
{/* Can't express nested options with react-select's type definition.
// @ts-ignore */}
<Async
autoFocus={true}
autoFocus
classes={classes}
styles={selectStyles}
inputId="go-to-select"
Expand Down
15 changes: 8 additions & 7 deletions docs-client/src/components/VariableList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ interface Props {

export default function({ title, variables, specification }: Props) {
const hasBean = variables.some(
(variable) =>
variable =>
!!variable.childFieldInfos && variable.childFieldInfos.length > 0,
);

const hasLocation = variables.some(
(variable) =>
variable =>
variable.location &&
variable.location.length > 0 &&
variable.location !== 'UNSPECIFIED',
Expand Down Expand Up @@ -113,7 +113,7 @@ const indentString = (indent: number, s: string): string => {

const formatRequirement = (s: string): string => {
const lowerCase = s.toLowerCase();
if ('unspecified' === lowerCase) {
if (lowerCase === 'unspecified') {
return '-';
}

Expand All @@ -133,7 +133,7 @@ const FieldInfo: React.FunctionComponent<FieldInfoProps> = ({
}) => {
const styles = useStyles();

const [expanded, toggleExpanded] = useReducer((value) => !value, false);
const [expanded, toggleExpanded] = useReducer(value => !value, false);

const hasChildren =
variable.childFieldInfos && variable.childFieldInfos.length > 0;
Expand Down Expand Up @@ -179,20 +179,20 @@ const FieldInfo: React.FunctionComponent<FieldInfoProps> = ({
);
};

const FieldInfos: React.FunctionComponent<FieldInfosProps> = (props) => {
const FieldInfos: React.FunctionComponent<FieldInfosProps> = props => {
const styles = useStyles();

const isEmpty = props.variables.length === 0;

let colSpanLength = 4;

if (props.variables.some((variable) => !!variable.location)) {
if (props.variables.some(variable => !!variable.location)) {
colSpanLength += 1;
}

if (
props.variables.some(
(variable) =>
variable =>
variable.childFieldInfos && variable.childFieldInfos.length > 0,
)
) {
Expand All @@ -205,6 +205,7 @@ const FieldInfos: React.FunctionComponent<FieldInfosProps> = (props) => {
<FieldInfo
hasLocation={props.hasLocation}
hidden={props.hidden}
// eslint-disable-next-line react/no-array-index-key
key={`${variable.name}-${index}`}
indent={props.indent}
variable={variable}
Expand Down
28 changes: 14 additions & 14 deletions docs-client/src/containers/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const AppDrawer: React.FunctionComponent<AppDrawerProps> = ({
{servicesSectionOpen ? <ExpandLess /> : <ExpandMore />}
</ListItem>
<Collapse in={servicesSectionOpen} timeout="auto">
{specification.getServices().map((service) => (
{specification.getServices().map(service => (
<div key={service.name}>
<ListItem
button
Expand All @@ -198,7 +198,7 @@ const AppDrawer: React.FunctionComponent<AppDrawerProps> = ({
{openServices[service.name] ? <ExpandLess /> : <ExpandMore />}
</ListItem>
<Collapse in={openServices[service.name]} timeout="auto">
{service.methods.map((method) => (
{service.methods.map(method => (
<ListItem
dense
key={`${service.name}/${method.name}/${method.httpMethod}`}
Expand All @@ -210,7 +210,7 @@ const AppDrawer: React.FunctionComponent<AppDrawerProps> = ({
}
>
<Grid container alignItems="center" spacing={2}>
<Grid item xs={'auto'}>
<Grid item xs="auto">
<Typography
className={httpMethodClass(method.httpMethod)}
>
Expand Down Expand Up @@ -244,7 +244,7 @@ const AppDrawer: React.FunctionComponent<AppDrawerProps> = ({
{enumsSectionOpen ? <ExpandLess /> : <ExpandMore />}
</ListItem>
<Collapse in={enumsSectionOpen} timeout="auto">
{specification.getEnums().map((enm) => (
{specification.getEnums().map(enm => (
<ListItem
dense
key={enm.name}
Expand Down Expand Up @@ -273,7 +273,7 @@ const AppDrawer: React.FunctionComponent<AppDrawerProps> = ({
{structsSectionOpen ? <ExpandLess /> : <ExpandMore />}
</ListItem>
<Collapse in={structsSectionOpen} timeout="auto">
{specification.getStructs().map((struct) => (
{specification.getStructs().map(struct => (
<ListItem
dense
key={struct.name}
Expand Down Expand Up @@ -302,7 +302,7 @@ const AppDrawer: React.FunctionComponent<AppDrawerProps> = ({
{exceptionsOpen ? <ExpandLess /> : <ExpandMore />}
</ListItem>
<Collapse in={exceptionsOpen} timeout="auto">
{specification.getExceptions().map((struct) => (
{specification.getExceptions().map(struct => (
<ListItem
dense
key={struct.name}
Expand Down Expand Up @@ -332,7 +332,7 @@ interface OpenServices {

const toggle = (current: boolean) => !current;

const App: React.FunctionComponent<Props> = (props) => {
const App: React.FunctionComponent<Props> = props => {
const [mobileDrawerOpen, setMobileDrawerOpen] = useState(false);
const [specification, setSpecification] = useState<
Specification | undefined
Expand All @@ -355,7 +355,7 @@ const App: React.FunctionComponent<Props> = (props) => {
const httpResponse = await fetch('specification.json');
const specificationData: SpecificationData = await httpResponse.json();
const initialSpecification = new Specification(specificationData);
initialSpecification.getServices().forEach((service) => {
initialSpecification.getServices().forEach(service => {
toggleOpenService(service.name);
});
setSpecification(initialSpecification);
Expand Down Expand Up @@ -466,14 +466,14 @@ const App: React.FunctionComponent<Props> = (props) => {
color="inherit"
noWrap
>
<a href="#" className={classes.mainHeader}>
<span className={classes.mainHeader}>
Armeria documentation service
{versions
? ` ${extractSimpleArtifactVersion(
versions.getArmeriaArtifactVersion(),
)}`
: ''}
</a>
</span>
</Typography>
<div style={{ flex: 1 }} />
<GotoSelect specification={specification} navigateTo={navigateTo} />
Expand Down Expand Up @@ -531,19 +531,19 @@ const App: React.FunctionComponent<Props> = (props) => {
<Route
exact
path="/"
render={(p) => <HomePage {...p} versions={versions} />}
render={p => <HomePage {...p} versions={versions} />}
/>
<Route
path="/enums/:name"
render={(p) => <EnumPage {...p} specification={specification} />}
render={p => <EnumPage {...p} specification={specification} />}
/>
<Route
path="/methods/:serviceName/:methodName/:httpMethod"
render={(p) => <MethodPage {...p} specification={specification} />}
render={p => <MethodPage {...p} specification={specification} />}
/>
<Route
path="/structs/:name"
render={(p) => <StructPage {...p} specification={specification} />}
render={p => <StructPage {...p} specification={specification} />}
/>
</main>
</div>
Expand Down
6 changes: 3 additions & 3 deletions docs-client/src/containers/EnumPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const EnumPage: React.FunctionComponent<Props> = ({ match, specification }) => {
return <>Not found.</>;
}

const hasIntValue = data.values.some((value) => !!value.intValue);
const hasDocString = data.values.some((value) => !!value.docString);
const hasIntValue = data.values.some(value => !!value.intValue);
const hasDocString = data.values.some(value => !!value.docString);

return (
<>
Expand All @@ -69,7 +69,7 @@ const EnumPage: React.FunctionComponent<Props> = ({ match, specification }) => {
</TableHead>
<TableBody>
{data.values.length > 0 ? (
data.values.map((value) => (
data.values.map(value => (
<TableRow key={value.name}>
<TableCell>
<code>{value.name}</code>
Expand Down
2 changes: 1 addition & 1 deletion docs-client/src/containers/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const HomePage: React.FunctionComponent<Props> = ({ versions }) => {
const tableRows: JSX.Element[] = [];

if (versions) {
versions.getVersions().forEach((version) => {
versions.getVersions().forEach(version => {
tableRows.push(
<TableRow key={version.artifactId}>
<TableCell>{version.artifactId}</TableCell>
Expand Down
Loading

0 comments on commit 7f89c81

Please sign in to comment.