Skip to content

Commit 29caf82

Browse files
committed
Add eslint-plugin-unicorn
1 parent 4c10aaa commit 29caf82

39 files changed

+192
-83
lines changed

.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const config = {
66
parserOptions: {},
77
extends: [
88
// /!\ Order matters: the next one overrides rules from the previous one
9+
'plugin:unicorn/recommended',
910
'plugin:jest/recommended',
1011
'airbnb',
1112
// Already done by Airbnb
@@ -104,6 +105,14 @@ const config = {
104105
'@typescript-eslint/ban-ts-ignore': 'off',
105106
'@typescript-eslint/explicit-module-boundary-types': 'off',
106107

108+
'unicorn/filename-case': 'off',
109+
'unicorn/prevent-abbreviations': 'off',
110+
'unicorn/catch-error-name': 'off',
111+
// [IE does not support for...of](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of#Browser_compatibility)
112+
'unicorn/no-for-loop': 'off',
113+
'unicorn/no-null': 'off',
114+
'unicorn/prefer-query-selector': 'off',
115+
107116
'jsx-a11y/label-has-associated-control': 'off',
108117

109118
'react/no-unescaped-entities': 'off',

examples/Bootstrap4/App.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ async function checkUsernameAvailability(value) {
2929
return !['john', 'paul', 'george', 'ringo'].includes(value.toLowerCase());
3030
}
3131

32+
function getInitialInputsState() {
33+
return {
34+
username: '',
35+
password: '',
36+
passwordConfirm: ''
37+
};
38+
}
39+
3240
function Form() {
3341
const form = useRef(null);
3442
const password = useRef(null);
3543

36-
function getInitialInputsState() {
37-
return {
38-
username: '',
39-
password: '',
40-
passwordConfirm: ''
41-
};
42-
}
43-
4444
const [inputs, setInputs] = useState(getInitialInputsState());
4545
const [signUpButtonDisabled, setSignUpButtonDisabled] = useState(false);
4646
const [resetButtonDisabled, setResetButtonDisabled] = useState(true);

examples/Bootstrap4/App.test.e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jest.setTimeout(20000); // 20s
55
function indent(text, indentation) {
66
// [Add a char to the start of each line in JavaScript using regular expression](https://stackoverflow.com/q/11939575)
77
// [Trim trailing spaces before newlines in a single multi-line string in JavaScript](https://stackoverflow.com/q/5568797)
8-
return text.replace(/^/gm, indentation).replace(/[^\S\r\n]+$/gm, '');
8+
return text.replace(/^/gm, indentation).replace(/[^\S\n\r]+$/gm, '');
99
}
1010

1111
beforeEach(async () => {

examples/MaterialUI/App.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ interface InputsState {
5656
passwordConfirm: string;
5757
}
5858

59+
function getInitialInputsState() {
60+
return {
61+
username: '',
62+
password: '',
63+
passwordConfirm: ''
64+
};
65+
}
66+
5967
function Form({ classes }: FormProps) {
6068
const form = useRef<FormWithConstraints | null>(null);
6169
const password = useRef<HTMLInputElement | null>(null);
6270

63-
function getInitialInputsState() {
64-
return {
65-
username: '',
66-
password: '',
67-
passwordConfirm: ''
68-
};
69-
}
70-
7171
const [inputs, setInputs] = useState<InputsState>(getInitialInputsState());
7272
const [signUpButtonDisabled, setSignUpButtonDisabled] = useState(false);
7373
const [resetButtonDisabled, setResetButtonDisabled] = useState(true);

examples/Password/App.test.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jest.setTimeout(20000); // 20s
44
function indent(text: string, indentation: string) {
55
// [Add a char to the start of each line in JavaScript using regular expression](https://stackoverflow.com/q/11939575)
66
// [Trim trailing spaces before newlines in a single multi-line string in JavaScript](https://stackoverflow.com/q/5568797)
7-
return text.replace(/^/gm, indentation).replace(/[^\S\r\n]+$/gm, '');
7+
return text.replace(/^/gm, indentation).replace(/[^\S\n\r]+$/gm, '');
88
}
99

1010
beforeEach(async () => {

examples/SignUp/App.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SignUp extends React.Component<Props, State> {
6767
return {
6868
// en-US => en, fr-FR => fr
6969
// eslint-disable-next-line react/destructuring-assignment
70-
language: this.props.i18n.language.substring(0, 2),
70+
language: this.props.i18n.language.slice(0, 2),
7171

7272
firstName: '',
7373
lastName: '',
@@ -141,11 +141,9 @@ class SignUp extends React.Component<Props, State> {
141141
target: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,
142142
forceValidateFields: boolean
143143
) {
144-
if (forceValidateFields) {
145-
await this.form!.validateFields(target);
146-
} else {
147-
await this.form!.validateFieldsWithoutFeedback(target);
148-
}
144+
await (forceValidateFields
145+
? this.form!.validateFields(target)
146+
: this.form!.validateFieldsWithoutFeedback(target));
149147

150148
this.setState(prevState => ({
151149
signUpButtonDisabled: !this.form!.isValid(),
@@ -170,11 +168,9 @@ class SignUp extends React.Component<Props, State> {
170168

171169
if (forceValidateFields) this.form!.resetFields(target);
172170

173-
if (_debounce) {
174-
await this.validateFieldsWithDebounce(target, forceValidateFields);
175-
} else {
176-
await this.validateFieldsWithoutDebounce(target, forceValidateFields);
177-
}
171+
await (_debounce
172+
? this.validateFieldsWithDebounce(target, forceValidateFields)
173+
: this.validateFieldsWithoutDebounce(target, forceValidateFields));
178174
}
179175

180176
handleHasWebsiteChange = (e: React.ChangeEvent<HTMLInputElement>) => {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"eslint-plugin-react": "^7.21.4",
4848
"eslint-plugin-react-hooks": "^4.1.2",
4949
"eslint-plugin-simple-import-sort": "^5.0.3",
50+
"eslint-plugin-unicorn": "^23.0.0",
5051
"husky": "^4.3.0",
5152
"lerna": "^3.22.1",
5253
"npm-run-all": "^4.1.5",

packages/react-form-with-constraints-bootstrap4/src/FieldFeedbacksEnzymeFix.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22

3-
import { FieldFeedbacks } from './index';
3+
import { FieldFeedbacks } from '.';
44

55
// FIXME [React 16 Fragments unsupported](https://github.com/airbnb/enzyme/issues/1213)
66
export class FieldFeedbacksEnzymeFix extends FieldFeedbacks {

packages/react-form-with-constraints-bootstrap4/src/SignUp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
22

33
import { checkUsernameAvailability } from '../../react-form-with-constraints/src/checkUsernameAvailability';
4+
import { Async, FieldFeedback, FormWithConstraints, Input } from '.';
45
import { FieldFeedbacksEnzymeFix as FieldFeedbacks } from './FieldFeedbacksEnzymeFix';
5-
import { Async, FieldFeedback, FormWithConstraints, Input } from './index';
66

77
export class SignUp extends React.Component {
88
form: FormWithConstraints | null = null;

packages/react-form-with-constraints-material-ui/src/FieldFeedbacksEnzymeFix.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22

3-
import { FieldFeedbacks } from './index';
3+
import { FieldFeedbacks } from '.';
44

55
// FIXME [React 16 Fragments unsupported](https://github.com/airbnb/enzyme/issues/1213)
66
export class FieldFeedbacksEnzymeFix extends FieldFeedbacks {

0 commit comments

Comments
 (0)