Skip to content

Commit bb9e206

Browse files
author
sam
committed
feat(jest): upgrade jest testing and linting
1 parent b2f352e commit bb9e206

22 files changed

Lines changed: 13928 additions & 235 deletions

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests_config/
2+
tests/

.eslintrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"env": {
3+
"jest": true
4+
},
5+
"extends": ["airbnb-base", "prettier"],
6+
"globals": {
7+
"run_spec": false
8+
}
9+
}

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: ["14.x"]
12+
node-version: ['14.x']
1313

1414
steps:
1515
- uses: actions/checkout@v2

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.prettierrc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @file Prettier configuration for Conformance
3+
* @version 1.0.6
4+
* @summary base config adapted from AirBNB to maximize performance
5+
* @schema http://json.schemastore.org/prettierrc
6+
*/
7+
8+
'use strict';
9+
10+
module.exports = {
11+
arrowParens: 'always',
12+
bracketSpacing: true,
13+
endOfLine: 'lf',
14+
jsxBracketSameLine: false,
15+
jsxSingleQuote: false,
16+
printWidth: 100,
17+
proseWrap: 'always',
18+
quoteProps: 'as-needed',
19+
semi: true,
20+
singleQuote: true,
21+
tabWidth: 2,
22+
trailingComma: 'all',
23+
useTabs: false,
24+
};

README.md

Lines changed: 74 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# [prettier-solidity-config](#)
22

3-
## Quickstart
3+
## Quickstart
44

55
```js
66
/**
7-
* @file prettier.config.js
8-
* @version v1.0.7
9-
* @summary Prettier Configuration for Solidity
10-
*/
7+
* @file prettier.config.js
8+
* @version v1.0.7
9+
* @summary Prettier Configuration for Solidity
10+
*/
1111

1212
'use strict';
1313

@@ -19,7 +19,7 @@ module.exports = prettierConfig;
1919

2020
Prettier configuration for Solidity
2121

22-
## Install
22+
## Install
2323

2424
#### Prettier
2525

@@ -28,6 +28,7 @@ npm i -D prettier prettier-plugin-solidity --save-exact
2828
```
2929

3030
#### with SolHint
31+
3132
```bash
3233
npm install --save-dev solhint solhint-plugin-prettier prettier prettier-plugin-solidity --save-exact
3334
```
@@ -43,26 +44,23 @@ npm install --save-dev solhint solhint-plugin-prettier prettier prettier-plugin-
4344

4445
## Abstract
4546

46-
This configuration is optimized to reduce **diff churn** and improve AST results.
47+
This configuration is optimized to reduce **diff churn** and improve AST results.
4748

48-
The following rules are employed, with specific reasonings to their choice (source: airbnb style guide):
49+
The following rules are employed, with specific reasonings to their choice (source: airbnb style
50+
guide):
4951

50-
### whitespace
52+
### whitespace
5153

5254
[source@airbnb/javascript#whitespace--in-braces](https://github.com/airbnb/javascript#whitespace--in-braces)
5355

5456
- 19.12 Add spaces inside curly braces. eslint: object-curly-spacing
5557

5658
```jsx
59+
// bad
60+
const foo = { clark: 'kent' };
5761

58-
59-
60-
// bad
61-
const foo = {clark: 'kent'};
62-
63-
// good
64-
const foo = { clark: 'kent' };
65-
62+
// good
63+
const foo = { clark: 'kent' };
6664
```
6765

6866
#### arrow-parens
@@ -71,69 +69,72 @@ The following rules are employed, with specific reasonings to their choice (sour
7169

7270
[source@airbnb/javascript#arrows--one-arg-parens](https://github.com/airbnb/javascript#arrows--one-arg-parens)
7371

74-
> Why? Minimizes diff churn when adding or removing arguments.
72+
> Why? Minimizes diff churn when adding or removing arguments.
73+
7574
```jsx
76-
// bad
77-
[1, 2, 3].map(x => x * x);
78-
79-
// good
80-
[1, 2, 3].map((x) => x * x);
81-
82-
// bad
83-
[1, 2, 3].map(number => (
84-
`A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`
85-
));
86-
87-
// good
88-
[1, 2, 3].map((number) => (
89-
`A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`
90-
));
91-
92-
// bad
93-
[1, 2, 3].map(x => {
94-
const y = x + 1;
95-
return x * y;
96-
});
97-
98-
// good
99-
[1, 2, 3].map((x) => {
100-
const y = x + 1;
101-
return x * y;
102-
});
75+
// bad
76+
[1, 2, 3].map((x) => x * x);
77+
78+
// good
79+
[1, 2, 3].map((x) => x * x);
80+
81+
// bad
82+
[1, 2, 3].map(
83+
(number) =>
84+
`A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`,
85+
);
86+
87+
// good
88+
[1, 2, 3].map(
89+
(number) =>
90+
`A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`,
91+
);
92+
93+
// bad
94+
[1, 2, 3].map((x) => {
95+
const y = x + 1;
96+
return x * y;
97+
});
98+
99+
// good
100+
[1, 2, 3].map((x) => {
101+
const y = x + 1;
102+
return x * y;
103+
});
103104
```
104105

105106
#### one var
106107

107108
- 13.2 Use one const or let declaration per variable or assignment. eslint: one-var
108109

109-
> Why? It’s easier to add new variable declarations this way, and you never have to worry about swapping out a ; for a ,
110-
> or introducing punctuation-only diffs. You can also step through each declaration with the debugger, instead of jumping through all of them at once.
110+
> Why? It’s easier to add new variable declarations this way, and you never have to worry about
111+
> swapping out a ; for a , or introducing punctuation-only diffs. You can also step through each
112+
> declaration with the debugger, instead of jumping through all of them at once.
111113
112114
##### [ref:eslint/rules/one-var](https://eslint.org/docs/rules/one-var)
113115

114116
```jsx
115-
// bad
116-
const items = getItems(),
117-
goSportsTeam = true,
118-
dragonball = 'z';
119-
120-
// bad
121-
// (compare to above, and try to spot the mistake)
122-
const items = getItems(),
123-
goSportsTeam = true;
124-
dragonball = 'z';
125-
126-
// good
127-
const items = getItems();
128-
const goSportsTeam = true;
129-
const dragonball = 'z';
117+
// bad
118+
const items = getItems(),
119+
goSportsTeam = true,
120+
dragonball = 'z';
121+
122+
// bad
123+
// (compare to above, and try to spot the mistake)
124+
const items = getItems(),
125+
goSportsTeam = true;
126+
dragonball = 'z';
127+
128+
// good
129+
const items = getItems();
130+
const goSportsTeam = true;
131+
const dragonball = 'z';
130132
```
131133

132134
#### 20.2 Additional trailing comma: Yup. eslint: comma-dangle
133135

134136
Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don’t have to worry about the trailing comma problem in legacy browsers.
135-
136-
137+
137138
```diff
138139
// bad - git diff without trailing comma
139140
const hero = {
@@ -154,19 +155,15 @@ const hero = {
154155
#### 8.6 Enforce the location of arrow function bodies with implicit returns. eslint: implicit-arrow-linebreak
155156

156157
```js
157-
// bad
158-
(foo) =>
159-
bar;
160-
161-
(foo) =>
162-
(bar);
163-
164-
// good
165-
(foo) => bar;
166-
(foo) => (bar);
167-
(foo) => (
168-
bar
169-
)
158+
// bad
159+
(foo) => bar;
160+
161+
(foo) => bar;
162+
163+
// good
164+
(foo) => bar;
165+
(foo) => bar;
166+
(foo) => bar;
170167
```
171168

172169
## License

index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run_spec('../tests/__snapshots__/jsfmt.spec.js.snap');

jest.config.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ module.exports = {
77
'!scripts/generateIndexes.js',
88
'src/**/*.js',
99
'!<rootDir>/node_modules/',
10-
'!src/prettier-comments/**/*.js'
10+
'!src/prettier-comments/**/*.js',
1111
],
1212
coverageDirectory: './coverage/',
1313
coverageThreshold: {
1414
global: {
1515
branches: 100,
1616
functions: 100,
1717
lines: 100,
18-
statements: 100
19-
}
18+
statements: 100,
19+
},
2020
},
2121
setupFiles: ['<rootDir>/tests_config/run_spec.js'],
2222
snapshotSerializers: ['<rootDir>/tests_config/raw-serializer.js'],
2323
testEnvironment: 'node',
2424
testRegex: 'jsfmt\\.spec\\.js$|__tests__/.*\\.js$|scripts/.*\\.test\\.js$',
2525
transform: {},
26-
watchPlugins: [
27-
'jest-watch-typeahead/filename',
28-
'jest-watch-typeahead/testname'
29-
]
26+
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
3027
};

0 commit comments

Comments
 (0)