Skip to content

Commit c3231ce

Browse files
committed
chore: ESLint/Prettier/Husky/lint-staged integration
1 parent 91999d4 commit c3231ce

File tree

11 files changed

+9093
-4063
lines changed

11 files changed

+9093
-4063
lines changed

.babelrc.js

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,62 @@
1-
'use strict'
1+
"use strict";
22

3-
const NODE_ENV = process.env.NODE_ENV || 'development'
4-
const __PROD__ = NODE_ENV === 'production'
5-
const __TEST__ = NODE_ENV === 'test'
3+
const PLUGINS_RE = /^(?:@babel\/|babel-)plugin-.+$/;
4+
const PRESETS_RE = /^@babel\/preset-.+$/;
65

7-
const pkg = require('./package')
6+
const NODE_ENV = process.env.NODE_ENV || "development";
7+
const __PROD__ = NODE_ENV === "production";
8+
const __TEST__ = NODE_ENV === "test";
89

9-
const plugins = {
10-
lodash: {},
11-
}
12-
13-
const presets = {
14-
'@babel/preset-env': {
15-
debug: !__TEST__,
16-
loose: true,
17-
shippedProposals: true,
18-
targets: __PROD__
19-
? (() => {
20-
let node = (pkg.engines || {}).node
21-
if (node !== undefined) {
22-
const trimChars = '^=>~'
23-
while (trimChars.includes(node[0])) {
24-
node = node.slice(1)
25-
}
26-
return { node: node }
27-
}
28-
})()
29-
: { browsers: '', node: 'current' },
30-
useBuiltIns: '@babel/polyfill' in (pkg.dependencies || {}) && 'usage',
10+
const configs = {
11+
"@babel/plugin-proposal-decorators": {
12+
legacy: true,
13+
},
14+
"@babel/preset-env"(pkg) {
15+
return {
16+
debug: !__TEST__,
17+
loose: true,
18+
shippedProposals: true,
19+
targets: __PROD__
20+
? (() => {
21+
let node = (pkg.engines || {}).node;
22+
if (node !== undefined) {
23+
const trimChars = "^=>~";
24+
while (trimChars.includes(node[0])) {
25+
node = node.slice(1);
26+
}
27+
return { node: node };
28+
}
29+
})()
30+
: { browsers: "", node: "current" },
31+
useBuiltIns: "@babel/polyfill" in (pkg.dependencies || {}) && "usage",
32+
};
3133
},
32-
}
34+
};
35+
36+
const getConfig = (key, ...args) => {
37+
const config = configs[key];
38+
return config === undefined
39+
? {}
40+
: typeof config === "function"
41+
? config(...args)
42+
: config;
43+
};
44+
45+
const plugins = {};
46+
const presets = {};
47+
const pkg = require("./package.json");
3348

3449
Object.keys(pkg.devDependencies || {}).forEach(name => {
35-
if (!(name in presets) && /@babel\/plugin-.+/.test(name)) {
36-
plugins[name] = {}
37-
} else if (!(name in presets) && /@babel\/preset-.+/.test(name)) {
38-
presets[name] = {}
50+
if (!(name in presets) && PLUGINS_RE.test(name)) {
51+
plugins[name] = getConfig(name, pkg);
52+
} else if (!(name in presets) && PRESETS_RE.test(name)) {
53+
presets[name] = getConfig(name, pkg);
3954
}
40-
})
55+
});
4156

4257
module.exports = {
4358
comments: !__PROD__,
4459
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
4560
plugins: Object.keys(plugins).map(plugin => [plugin, plugins[plugin]]),
4661
presets: Object.keys(presets).map(preset => [preset, presets[preset]]),
47-
}
62+
};

.editorconfig

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,12 @@
33
# Julien Fontanet's configuration
44
# https://gist.github.com/julien-f/8096213
55

6-
# Top-most EditorConfig file.
76
root = true
87

9-
# Common config.
108
[*]
119
charset = utf-8
1210
end_of_line = lf
13-
insert_final_newline = true
14-
trim_trailing_whitespace = true
15-
16-
# CoffeeScript
17-
#
18-
# https://github.com/polarmobile/coffeescript-style-guide/blob/master/README.md
19-
[*.{,lit}coffee]
20-
indent_size = 2
21-
indent_style = space
22-
23-
# Markdown
24-
[*.{md,mdwn,mdown,markdown}]
25-
indent_size = 4
26-
indent_style = space
27-
trim_trailing_whitespace = false
28-
29-
# Package.json
30-
#
31-
# This indentation style is the one used by npm.
32-
[package.json]
33-
indent_size = 2
34-
indent_style = space
35-
36-
# Pug (Jade)
37-
[*.{jade,pug}]
38-
indent_size = 2
39-
indent_style = space
40-
41-
# JavaScript
42-
#
43-
# Two spaces seems to be the standard most common style, at least in
44-
# Node.js (http://nodeguide.com/style.html#tabs-vs-spaces).
45-
[*.{js,jsx,ts,tsx}]
46-
indent_size = 2
47-
indent_style = space
48-
49-
# Less
50-
[*.less]
51-
indent_size = 2
52-
indent_style = space
53-
54-
# Sass
55-
#
56-
# Style used for http://libsass.com
57-
[*.s[ac]ss]
58-
indent_size = 2
59-
indent_style = space
60-
61-
# YAML
62-
#
63-
# Only spaces are allowed.
64-
[*.yaml]
6511
indent_size = 2
6612
indent_style = space
13+
insert_final_newline = true
14+
trim_trailing_whitespace = true

.eslintrc.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
module.exports = {
2-
extends: ['standard'],
3-
parser: 'babel-eslint',
2+
extends: [
3+
// standard configuration
4+
"standard",
5+
6+
// https://github.com/mysticatea/eslint-plugin-node#-rules
7+
"plugin:node/recommended",
8+
9+
// disable rules handled by prettier
10+
"prettier",
11+
"prettier/standard",
12+
],
13+
14+
parser: "babel-eslint",
15+
416
rules: {
5-
'comma-dangle': ['error', 'always-multiline'],
6-
'no-var': 'error',
7-
'node/no-extraneous-import': 'error',
8-
'node/no-extraneous-require': 'error',
9-
'node/no-missing-require': 'error',
10-
'node/no-missing-import': 'error',
11-
'prefer-const': 'error',
17+
// prefer let/const over var
18+
"no-var": "error",
19+
20+
// prefer const over let when possible
21+
//
22+
// should be included in standard: https://github.com/standard/eslint-config-standard/pull/133/
23+
"prefer-const": "error",
24+
25+
// detect incorrect import
26+
"node/no-extraneous-import": "error",
27+
"node/no-missing-import": "error",
28+
29+
// uncomment if you are using a builder like Babel
30+
"node/no-unsupported-features/es-syntax": "off",
1231
},
13-
}
32+
};

.prettierrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
// this really improves diffs
3+
trailingComma: "es5",
4+
};

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ node_js:
33
- stable
44
- 8
55
- 6
6-
- 4
76

87
# Use containers.
98
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,53 +24,53 @@ Installation of the [npm package](https://npmjs.org/package/limit-concurrency-de
2424
Simply apply the decorator to a method:
2525

2626
```js
27-
import limit from 'limit-concurrency-decorator'
27+
import limit from "limit-concurrency-decorator";
2828

2929
class HttpClient {
3030
@limit(2)
31-
get () {
31+
get() {
3232
// ...
3333
}
3434
}
3535

36-
const client = new HttpClient()
36+
const client = new HttpClient();
3737

3838
// these calls will run in parallel
39-
client.get('http://example.net/')
40-
client.get('http://example2.net/')
39+
client.get("http://example.net/");
40+
client.get("http://example2.net/");
4141

4242
// this call will wait for the 2 previous to finish
43-
client.get('http://example3.net/')
43+
client.get("http://example3.net/");
4444
```
4545

4646
Or a simple function as a wrapper:
4747

4848
```js
49-
import httpRequest from 'http-request-plus'
49+
import httpRequest from "http-request-plus";
5050

51-
const httpRequestLimited = limit(2)(httpRequest)
51+
const httpRequestLimited = limit(2)(httpRequest);
5252

5353
// these calls will run in parallel
54-
httpRequestLimited('http://example.net/')
55-
httpRequestLimited('http://example2.net/')
54+
httpRequestLimited("http://example.net/");
55+
httpRequestLimited("http://example2.net/");
5656

5757
// this call will wait for the 2 previous to finish
58-
httpRequestLimited('http://example3.net/')
58+
httpRequestLimited("http://example3.net/");
5959
```
6060

6161
The limit can be shared:
6262

6363
```js
64-
const myLimit = limit(2)
64+
const myLimit = limit(2);
6565

6666
class HttpClient {
6767
@myLimit
68-
post () {
68+
post() {
6969
// ...
7070
}
7171

7272
@myLimit
73-
put () {
73+
put() {
7474
// ...
7575
}
7676
}
@@ -79,32 +79,32 @@ class HttpClient {
7979
With `FAIL_ON_QUEUE` you can fail early instead of waiting:
8080

8181
```js
82-
import { FAIL_ON_QUEUE } from 'limit-concurrency-decorator'
82+
import { FAIL_ON_QUEUE } from "limit-concurrency-decorator";
8383

8484
try {
85-
await httpRequestLimited(FAIL_ON_QUEUE, 'http://example2.net')
85+
await httpRequestLimited(FAIL_ON_QUEUE, "http://example2.net");
8686
} catch (error) {
87-
error.message // 'no available place in queue'
87+
error.message; // 'no available place in queue'
8888
}
8989
```
9090

9191
Custom termination:
9292

9393
```js
9494
const httpRequestLimited = limit(2, async promise => {
95-
const stream = await promise
95+
const stream = await promise;
9696
await new Promise(resolve => {
97-
stream.on('end', resolve)
98-
stream.on('error', reject)
99-
})
100-
})(httpRequest)
97+
stream.on("end", resolve);
98+
stream.on("error", reject);
99+
});
100+
})(httpRequest);
101101

102102
// these calls will run in parallel
103-
httpRequestLimited('http://example.net/')
104-
httpRequestLimited('http://example2.net/')
103+
httpRequestLimited("http://example.net/");
104+
httpRequestLimited("http://example2.net/");
105105

106106
// this call will wait for the 2 previous responses to have been read entirely
107-
httpRequestLimited('http://example3.net/')
107+
httpRequestLimited("http://example3.net/");
108108
```
109109

110110
## Development
@@ -128,7 +128,7 @@ httpRequestLimited('http://example3.net/')
128128

129129
## Contributions
130130

131-
Contributions are *very* welcomed, either on the documentation or on
131+
Contributions are _very_ welcomed, either on the documentation or on
132132
the code.
133133

134134
You may:

0 commit comments

Comments
 (0)