Skip to content

Commit bc53f59

Browse files
authored
chore: add eslint and configs. (#255)
Format the code and fix all linting issues
1 parent 5820be2 commit bc53f59

27 files changed

+10160
-1575
lines changed

.eslintrc.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module.exports = {
2+
root: true,
3+
4+
ignorePatterns: [
5+
'node_modules',
6+
'coverage',
7+
'dist',
8+
'.github/workflows',
9+
'.husky',
10+
'CHANGELOG.md',
11+
],
12+
13+
parserOptions: {
14+
project: './tsconfig.eslint.json',
15+
tsconfigRootDir: __dirname,
16+
extraFileExtensions: ['.mdx', '.md'],
17+
},
18+
19+
overrides: [
20+
{
21+
files: ['*.js', '*.ts', '*.jsx', '*.tsx'],
22+
extends: ['@react-hookz/eslint-config/react'],
23+
rules: {
24+
// ToDo: remove below after refactoring
25+
'no-underscore-dangle': 'off',
26+
'import/no-default-export': 'off',
27+
'no-bitwise': 'off',
28+
'@typescript-eslint/naming-convention': 'off',
29+
'react/destructuring-assignment': 'off',
30+
'unicorn/consistent-destructuring': 'off',
31+
'react/no-unused-class-component-methods': 'off',
32+
'@typescript-eslint/no-unsafe-call': 'off',
33+
'@typescript-eslint/no-explicit-any': 'off',
34+
'@typescript-eslint/no-unsafe-member-access': 'off',
35+
'@typescript-eslint/no-unsafe-assignment': 'off',
36+
'@typescript-eslint/no-unsafe-argument': 'off',
37+
'no-use-before-define': 'off',
38+
'@typescript-eslint/no-non-null-assertion': 'off',
39+
},
40+
},
41+
{
42+
files: ['tests/*.js', 'tests/*.ts', 'tests/*.jsx', 'tests/*.tsx'],
43+
extends: ['@react-hookz/eslint-config/react'],
44+
rules: {
45+
// ToDo: remove below after refactoring
46+
'no-underscore-dangle': 'off',
47+
'import/no-default-export': 'off',
48+
'@typescript-eslint/naming-convention': 'off',
49+
'@typescript-eslint/no-unsafe-call': 'off',
50+
'@typescript-eslint/no-explicit-any': 'off',
51+
'@typescript-eslint/no-unsafe-member-access': 'off',
52+
'@typescript-eslint/no-unsafe-assignment': 'off',
53+
'@typescript-eslint/no-unsafe-argument': 'off',
54+
'no-prototype-builtins': 'off',
55+
'@typescript-eslint/no-unused-vars': 'off',
56+
'no-bitwise': 'off',
57+
'func-names': 'off',
58+
'@typescript-eslint/restrict-plus-operands': 'off',
59+
'react/jsx-no-bind': 'off',
60+
'react/no-unused-state': 'off',
61+
'react/destructuring-assignment': 'off',
62+
'unicorn/consistent-destructuring': 'off',
63+
'react/no-unused-class-component-methods': 'off',
64+
'no-use-before-define': 'off',
65+
'@typescript-eslint/no-non-null-assertion': 'off',
66+
},
67+
},
68+
{
69+
files: ['*.md', '*.mdx'],
70+
extends: ['@react-hookz/eslint-config/mdx'],
71+
},
72+
],
73+
};

.github/workflows/ci.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ env:
1313
HUSKY: 0
1414

1515
jobs:
16+
lint:
17+
name: "Lint"
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: "Checkout"
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
25+
- uses: actions/setup-node@v3
26+
with:
27+
node-version: 16
28+
29+
- uses: bahmutov/npm-install@v1
30+
with:
31+
useRollingCache: true
32+
install-command: yarn --frozen-lockfile
33+
34+
- name: "Lint"
35+
run: yarn lint -f @jamesacarr/github-actions
36+
1637
test:
1738
name: "Test"
1839
runs-on: ubuntu-latest
@@ -44,7 +65,7 @@ jobs:
4465
dependabot-merge:
4566
name: "Dependabot automerge"
4667
runs-on: ubuntu-latest
47-
needs: [ "test" ]
68+
needs: [ "test", "lint" ]
4869
permissions:
4970
pull-requests: write
5071
contents: write

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const config = require("@react-hookz/eslint-config/.prettierrc.js");
2+
3+
module.exports = config;

README.md

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ Underneath `react-scrollbars-custom` uses `requestAnimationFrame` loop, which ch
5050
The `<Scrollbar />` component works out of the box, with only need of `width` and `height` to be set, inline or via CSS;
5151

5252
```typescript jsx
53-
import { Scrollbar } from "react-scrollbars-custom";
53+
import { Scrollbar } from 'react-scrollbars-custom';
5454

5555
<Scrollbar style={{ width: 250, height: 250 }}>
5656
<p>Hello world!</p>
57-
</Scrollbar>
57+
</Scrollbar>;
5858
```
5959

6060
### Internet Explorer
@@ -75,9 +75,7 @@ It'll change the generated markup:
7575
// scrollbar.scrollerElement
7676
<div class="ScrollbarsCustom native trackYVisible trackXVisible">
7777
// scrollbar.contentElement - the one that holds tour content
78-
<div class="ScrollbarsCustom-Content">
79-
// YOUR CONTENT IS HERE
80-
</div>
78+
<div class="ScrollbarsCustom-Content">// YOUR CONTENT IS HERE</div>
8179
</div>
8280
```
8381

@@ -113,51 +111,51 @@ You can do absolutely what ever you want y simply passing renderer SFC to the ne
113111
114112
```typescript jsx
115113
<Scrollbar
116-
renderer={props => {
114+
renderer={(props) => {
117115
const { elementRef, ...restProps } = props;
118116
return <span {...restProps} ref={elementRef} className="MyAwesomeScrollbarsHolder" />;
119117
}}
120118
wrapperProps={{
121-
renderer: props => {
119+
renderer: (props) => {
122120
const { elementRef, ...restProps } = props;
123121
return <span {...restProps} ref={elementRef} className="MyAwesomeScrollbarsWrapper" />;
124-
}
122+
},
125123
}}
126124
scrollerProps={{
127-
renderer: props => {
125+
renderer: (props) => {
128126
const { elementRef, ...restProps } = props;
129127
return <span {...restProps} ref={elementRef} className="MyAwesomeScrollbarsScroller" />;
130-
}
128+
},
131129
}}
132130
contentProps={{
133-
renderer: props => {
131+
renderer: (props) => {
134132
const { elementRef, ...restProps } = props;
135133
return <span {...restProps} ref={elementRef} className="Content" />;
136-
}
134+
},
137135
}}
138136
trackXProps={{
139-
renderer: props => {
137+
renderer: (props) => {
140138
const { elementRef, ...restProps } = props;
141139
return <span {...restProps} ref={elementRef} className="TrackX" />;
142-
}
140+
},
143141
}}
144142
trackYProps={{
145-
renderer: props => {
143+
renderer: (props) => {
146144
const { elementRef, ...restProps } = props;
147145
return <span {...restProps} ref={elementRef} className="trackY" />;
148-
}
146+
},
149147
}}
150148
thumbXProps={{
151-
renderer: props => {
149+
renderer: (props) => {
152150
const { elementRef, ...restProps } = props;
153151
return <span {...restProps} ref={elementRef} className="ThUmBX" />;
154-
}
152+
},
155153
}}
156154
thumbYProps={{
157-
renderer: props => {
155+
renderer: (props) => {
158156
const { elementRef, ...restProps } = props;
159157
return <span {...restProps} ref={elementRef} className="tHuMbY" />;
160-
}
158+
},
161159
}}
162160
/>
163161
```
@@ -172,9 +170,7 @@ You can do absolutely what ever you want y simply passing renderer SFC to the ne
172170
// scrollbar.scrollerElement - the one that actually has browser's scrollbars
173171
<div class="ScrollbarsCustom-Scroller">
174172
// scrollbar.contentElement - the one that holds tour content
175-
<div class="ScrollbarsCustom-Content">
176-
// YOUR CONTENT IS HERE
177-
</div>
173+
<div class="ScrollbarsCustom-Content">// YOUR CONTENT IS HERE</div>
178174
</div>
179175
</div>
180176
// scrollbar.trackYElement

karma.conf.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
// eslint-disable-next-line unicorn/prefer-module
12
module.exports = (cfg) => {
23
cfg.set({
3-
browsers: ["ChromeHeadless"],
4+
browsers: ['ChromeHeadless'],
45

56
singleRun: true,
67
autoWatch: false,
78

8-
frameworks: ["jasmine", "karma-typescript"],
9-
reporters: ["progress", "karma-typescript"],
9+
frameworks: ['jasmine', 'karma-typescript'],
10+
reporters: ['progress', 'karma-typescript'],
1011
preprocessors: {
11-
"**/*.ts": "karma-typescript",
12-
"**/*.tsx": "karma-typescript",
12+
'**/*.ts': 'karma-typescript',
13+
'**/*.tsx': 'karma-typescript',
1314
},
1415

15-
files: ["./src/**/*.ts", "./src/**/*.tsx", "./tests/**/*.spec.ts", "./tests/**/*.spec.tsx"],
16+
files: ['./src/**/*.ts', './src/**/*.tsx', './tests/**/*.spec.ts', './tests/**/*.spec.tsx'],
1617

1718
client: {
1819
jasmine: {
@@ -23,33 +24,33 @@ module.exports = (cfg) => {
2324
karmaTypescriptConfig: {
2425
bundlerOptions: {
2526
constants: {
26-
"process.env": {
27-
NODE_ENV: "production",
27+
'process.env': {
28+
NODE_ENV: 'production',
2829
},
2930
},
3031
},
3132
compilerOptions: {
32-
target: "es2017",
33-
module: "commonjs",
34-
moduleResolution: "node",
35-
jsx: "react",
36-
lib: ["dom", "es2017"],
33+
target: 'es2017',
34+
module: 'commonjs',
35+
moduleResolution: 'node',
36+
jsx: 'react',
37+
lib: ['dom', 'es2017'],
3738
},
3839
coverageOptions: {
3940
exclude: /(node_modules|tests|spec)/i,
4041
},
4142
reports: {
4243
lcovonly: {
43-
directory: "./coverage",
44-
subdirectory: () => "",
45-
filename: "lcov.info",
44+
directory: './coverage',
45+
subdirectory: () => '',
46+
filename: 'lcov.info',
4647
},
4748
html: {
48-
directory: "./coverage",
49-
subdirectory: () => "",
49+
directory: './coverage',
50+
subdirectory: () => '',
5051
},
5152
},
52-
include: ["./src/**/*", "./tests/**/*"],
53+
include: ['./src/**/*', './tests/**/*'],
5354
},
5455
});
5556
};

package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,23 @@
4747
"devDependencies": {
4848
"@babel/core": "^7.18.9",
4949
"@babel/preset-env": "^7.18.9",
50+
"@jamesacarr/eslint-formatter-github-actions": "^0.1.0",
51+
"@react-hookz/eslint-config": "^1.6.1",
5052
"@types/jasmine": "^4.0.3",
5153
"@types/karma": "^6.3.3",
52-
"@types/react": "^16.9.35",
54+
"@types/react": "^17",
55+
"@types/react-dom": "^17",
5356
"cross-env": "^7.0.3",
5457
"jasmine-core": "^4.3.0",
5558
"karma": "^6.4.0",
5659
"karma-chrome-launcher": "^3.1.1",
5760
"karma-coverage": "^2.2.0",
5861
"karma-jasmine": "^5.1.0",
5962
"karma-typescript": "^5.5.3",
60-
"react": "^16.13.1",
61-
"react-dom": "^16.13.1",
63+
"lint-staged": "^13.0.3",
64+
"prettier": "^2.7.1",
65+
"react": "^17",
66+
"react-dom": "^17",
6267
"rimraf": "^3.0.2",
6368
"rollup": "^2.77.0",
6469
"rollup-plugin-babel": "^4.4.0",
@@ -67,12 +72,14 @@
6772
"tslib": "^2.0.0",
6873
"typescript": "^4.7.4"
6974
},
75+
"lint-staged": {
76+
"*.{js,jsx,ts,tsx,md,mdx}": "eslint --fix"
77+
},
7078
"scripts": {
79+
"lint": "eslint ./ --ext ts,js,tsx,jsx,md,mdx",
80+
"lint:fix": "yarn lint --fix",
7181
"devserver": "cd ./testbench && npm i && npm run devserver",
7282
"build": "rimraf ./dist && rollup --config",
7383
"test": "cross-env NODE_ENV=production karma start"
74-
},
75-
"prettier": {
76-
"printWidth": 120
7784
}
7885
}

0 commit comments

Comments
 (0)