Skip to content

Commit 833a8e7

Browse files
committed
Breaking: drop Node 4 and ESLint 3 supports
Also this commit adds shareable configs for me.
1 parent 6e43222 commit 833a8e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2610
-706
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
!.eslintrc.*

.eslintrc.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @author Toru Nagashima
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
"use strict"
6+
7+
const fs = require("fs")
8+
const path = require("path")
9+
const { version } = require("./package.json")
10+
const selfPath = __dirname
11+
const modulePath = path.resolve(
12+
__dirname,
13+
"node_modules/eslint-plugin-mysticatea"
14+
)
15+
16+
// Make symlink to use itself.
17+
if (!fs.existsSync(modulePath)) {
18+
fs.symlinkSync(selfPath, modulePath, "junction")
19+
}
20+
21+
module.exports = {
22+
extends: ["plugin:mysticatea/es2015", "plugin:mysticatea/+eslint-plugin"],
23+
rules: {
24+
"mysticatea/eslint-plugin/require-meta-docs-url": [
25+
"error",
26+
{
27+
pattern: `https://github.com/mysticatea/eslint-plugin/blob/v${version}/docs/rules/{{name}}.md`,
28+
},
29+
],
30+
},
31+
}

.eslintrc.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/.nyc_output
22
/coverage
3-
/index.js
43
/node_modules
54
/npm-debug.log
65
/test.js

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ sudo: false
22

33
language: node_js
44
node_js:
5-
- "4"
65
- "6"
76
- "8"
7+
- "10"
88

99
env:
1010
- ESLINT_VERSION=4
11-
- ESLINT_VERSION=3
12-
- ESLINT_VERSION=3.1
1311

1412
before_script:
1513
- npm i --no-save eslint@$ESLINT_VERSION; true
1614

1715
script:
18-
- if [ $ESLINT_VERSION = 4 ]; then npm run lint; fi
16+
- npm run lint
1917
- npm test
2018

2119
after_success:

README.md

Lines changed: 103 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,105 @@
66
[![codecov](https://codecov.io/gh/mysticatea/eslint-plugin/branch/master/graph/badge.svg)](https://codecov.io/gh/mysticatea/eslint-plugin)
77
[![Dependency Status](https://david-dm.org/mysticatea/eslint-plugin.svg)](https://david-dm.org/mysticatea/eslint-plugin)
88

9-
Additional ESLint rules.
9+
Additional ESLint rules and ESLint configurations for me.
1010

11-
## :cd: Installation
11+
## 💿 Installation
1212

1313
```
1414
npm install --save-dev eslint eslint-plugin-mysticatea
1515
```
1616

1717
### Requirements
1818

19-
- Node.js `^4.0.0`, `^6.0.0`, or newer.
20-
- ESLint `^3.1.0`, or newer.
19+
- Node.js `6`, `8`, `9` and newer versions.
20+
- ESLint `^4.19.1`.
2121

22-
## :book: Usage
22+
## 📖 Usage
2323

2424
Write in your ESLint configurations: http://eslint.org/docs/user-guide/configuring#using-the-configuration-from-a-plugin
2525

26+
### Configs
27+
28+
- `plugin:mysticatea/es2018` ... Basic configuration for ES2018.
29+
- `plugin:mysticatea/es2017` ... Basic configuration for ES2017.
30+
- `plugin:mysticatea/es2016` ... Basic configuration for ES2016.
31+
- `plugin:mysticatea/es2015` ... Basic configuration for ES2015.
32+
- `plugin:mysticatea/es5` ... Basic configuration for ES5.
33+
- `plugin:mysticatea/+modules` ... Additional configuration for ES modules.
34+
- `plugin:mysticatea/+browser` ... Additional configuration for browser environment.
35+
- `plugin:mysticatea/+node` ... Additional configuration for Node.js environment.
36+
- `plugin:mysticatea/+eslint-plugin` ... Additional configuration for ESLint plugins. This includes `plugin:mysticatea/+node` setting.
37+
38+
#### Details
39+
40+
The main configurations `plugin:mysticatea/es*` does:
41+
42+
- detect bug-like code by ESLint rules.
43+
- enforce whitespace style by Prettier.
44+
- handle the `.ts` files as TypeScript then check by `typescript-eslint-parser` and `eslint-plugin-typescript`.
45+
- handle the `.vue` files as Vue.js SFC then check by `vue-eslint-parser` and `eslint-plugin-vue`.
46+
- handle the files in `test`/`tests` directory as `mocha`'s test code.
47+
- handle the files in `scripts` directory as Node.js environment.
48+
- handle the `.eslintrc.js` file as a Node.js script.
49+
- handle the `webpack.config.js` file as a Node.js script.
50+
- handle the `rollup.config.js` file as an ES module.
51+
52+
You can use combination of a main configuration and some additional configurations.
53+
For examples:
54+
55+
##### For Node.js
56+
57+
```json
58+
{
59+
"extends": [
60+
"plugin:mysticatea/es2015",
61+
"plugin:mysticatea/+node"
62+
]
63+
}
64+
```
65+
66+
> It handles `.js` files as scripts and `.mjs` files as modules.
67+
68+
##### For Browsers
69+
70+
```json
71+
{
72+
"extends": [
73+
"plugin:mysticatea/es2015",
74+
"plugin:mysticatea/+browser"
75+
]
76+
}
77+
```
78+
79+
##### For Browsers with ES modules
80+
81+
```json
82+
{
83+
"extends": [
84+
"plugin:mysticatea/es2015",
85+
"plugin:mysticatea/+modules",
86+
"plugin:mysticatea/+browser"
87+
]
88+
}
89+
```
90+
91+
##### For ESLint plugins
92+
93+
```json
94+
{
95+
"extends": [
96+
"plugin:mysticatea/es2015",
97+
"plugin:mysticatea/+eslint-plugin"
98+
]
99+
}
100+
```
101+
26102
### Rules
27103

104+
This plugin has some original rules and foreign rules.
105+
106+
#### Original rules
107+
28108
- [mysticatea/arrow-parens](docs/rules/arrow-parens.md) enforces parens of argument lists (excludes too redundant parens) (fixable).
29109
- [mysticatea/block-scoped-var](docs/rules/block-scoped-var.md) handles variables which are declared by `var` declaration as block-scoped. It disallows redeclarations, uses from outside of the scope, shadowing.
30110
- [mysticatea/no-instanceof-array](docs/rules/no-instanceof-array.md) disallows 'instanceof' for Array (fixable).
@@ -35,58 +115,27 @@ Write in your ESLint configurations: http://eslint.org/docs/user-guide/configuri
35115
- [mysticatea/no-useless-rest-spread](docs/rules/no-useless-rest-spread.md) disallows unnecessary rest/spread operators (fixable).
36116
- [mysticatea/prefer-for-of](docs/rules/prefer-for-of.md) requires `for-of` statements instead of `Array#forEach` or something like (fixable).
37117

38-
### Example
118+
#### Foreign rules
39119

40-
**.eslintrc.json**
120+
- All `mysticatea/eslint-comments/*` rules are imported from [eslint-plugin-eslint-comments](https://www.npmjs.com/package/eslint-plugin-eslint-comments).
121+
- All `mysticatea/eslint-plugin/*` rules are imported from [eslint-plugin-eslint-plugin](https://www.npmjs.com/package/eslint-plugin-eslint-plugin).
122+
- All `mysticatea/node/*` rules are imported from [eslint-plugin-node](https://www.npmjs.com/package/eslint-plugin-node).
123+
- All `mysticatea/ts/*` rules are imported from [eslint-plugin-typescript](https://www.npmjs.com/package/eslint-plugin-typescript).
124+
- All `mysticatea/vue/*` rules are imported from [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue).
125+
- The `mysticatea/prettier` rule is imported from [eslint-plugin-prettier](https://www.npmjs.com/package/eslint-plugin-prettier).
41126

42-
```json
43-
{
44-
"plugins": [
45-
"mysticatea"
46-
],
47-
"rules": {
48-
"mysticatea/arrow-parens": "error",
49-
"mysticatea/block-scoped-var": "error",
50-
"mysticatea/no-instanceof-array": "error",
51-
"mysticatea/no-instanceof-wrapper": "error",
52-
"mysticatea/no-literal-call": "error",
53-
"mysticatea/no-this-in-static": "error",
54-
"mysticatea/no-use-ignored-vars": "error",
55-
"mysticatea/no-useless-rest-spread": "error",
56-
"mysticatea/prefer-for-of": "error",
57-
"arrow-parens": "off",
58-
"block-scoped-var": "off",
59-
"no-redeclare": "off"
60-
}
61-
}
62-
```
127+
> **Q:** Why don't you use those plugins directly?<br>
128+
> **A:** The combination with shareable configs and plugins has some problems because shareable configs were not designed to be used with plugins. @nzakas illustrated a way to use plugins as shareable configs together with other plugins in the discussion [eslint/eslint#3458](https://github.com/eslint/eslint/issues/3458#issuecomment-257161846). This is the way.
129+
130+
## 🚥 Semantic Versioning Policy
63131

64-
## :anchor: Semantic Versioning Policy
65-
66-
`eslint-plugin-mysticatea` follows [semantic versioning](http://semver.org/) and [ESLint's Semantic Versioning Policy](https://github.com/eslint/eslint#semantic-versioning-policy).
67-
68-
- Patch release (intended to not break your lint build)
69-
- A bug fix in a rule that results in `eslint-plugin-mysticatea` reporting fewer errors.
70-
- Improvements to documentation.
71-
- Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
72-
- Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
73-
- Minor release (might break your lint build)
74-
- A bug fix in a rule that results in `eslint-plugin-mysticatea` reporting more errors.
75-
- A new rule is created.
76-
- A new option to an existing rule is created.
77-
- An existing rule is deprecated.
78-
- Major release (likely to break your lint build)
79-
- A support for old Node version is dropped.
80-
- A support for old ESLint version is dropped.
81-
- An existing rule is removed.
82-
- An existing option of a rule is removed.
83-
- An existing config is updated.
84-
85-
## :newspaper: Changelog
132+
This plugin follows [semantic versioning](http://semver.org/) and [ESLint's Semantic Versioning Policy](https://github.com/eslint/eslint#semantic-versioning-policy).
133+
134+
## 📰 Changelog
86135

87136
- [GitHub Releases](https://github.com/mysticatea/eslint-plugin/releases)
88137

89-
## :muscle: Contributing
138+
## ❤️ Contributing
90139

91140
Welcome contributing!
92141

@@ -95,6 +144,7 @@ Please use GitHub's Issues/PRs.
95144
### Development Tools
96145

97146
- `npm test` runs tests and measures coverage.
98-
- `npm run watch` runs tests and measures coverage when source code are changed.
99-
- `npm run coverage` shows the coverage result of `npm test` command.
100147
- `npm run clean` removes the coverage result of `npm test` command.
148+
- `npm run coverage` shows the coverage result of `npm test` command.
149+
- `npm run update` updates auto-generated files.
150+
- `npm run watch` runs tests and measures coverage when source code are changed.

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @author Toru Nagashima
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
"use strict"
6+
7+
module.exports = {
8+
configs: require("./lib/configs"),
9+
processors: {
10+
".vue": require("eslint-plugin-vue").processors[".vue"],
11+
},
12+
rules: require("./lib/rules"),
13+
utils: {
14+
merge: require("./lib/utils").merge,
15+
},
16+
}

lib/configs.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* DON'T EDIT THIS FILE WHICH WAS GENERATED BY './scripts/generate-configs.js'.
3+
*/
4+
"use strict"
5+
6+
module.exports = {
7+
"+browser": require("./configs/+browser"),
8+
"+eslint-plugin": require("./configs/+eslint-plugin"),
9+
"+modules": require("./configs/+modules"),
10+
"+node": require("./configs/+node"),
11+
es2015: require("./configs/es2015"),
12+
es2016: require("./configs/es2016"),
13+
es2017: require("./configs/es2017"),
14+
es2018: require("./configs/es2018"),
15+
es5: require("./configs/es5"),
16+
}

lib/configs/+browser.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @author Toru Nagashima
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
"use strict"
6+
7+
const originalGlobals = require("globals").browser
8+
const globals = {}
9+
const allows = new Set([
10+
"atob",
11+
"btoa",
12+
"cancelAnimationFrame",
13+
"document",
14+
"fetch",
15+
"indexedDB",
16+
"localStorage",
17+
"matchMedia",
18+
"requestAnimationFrame",
19+
"sessionStorage",
20+
"window",
21+
])
22+
23+
for (const key of Object.keys(originalGlobals)) {
24+
if (key[0] === key[0].toUpperCase() || allows.has(key)) {
25+
globals[key] = originalGlobals[key]
26+
}
27+
}
28+
29+
module.exports = {
30+
globals,
31+
}

lib/configs/+eslint-plugin.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @author Toru Nagashima
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
"use strict"
6+
7+
module.exports = {
8+
extends: ["plugin:mysticatea/+node"],
9+
rules: {
10+
// Enabled rules
11+
"mysticatea/eslint-plugin/consistent-output": "error",
12+
"mysticatea/eslint-plugin/fixer-return": "error",
13+
"mysticatea/eslint-plugin/no-deprecated-context-methods": "error",
14+
"mysticatea/eslint-plugin/no-deprecated-report-api": "error",
15+
"mysticatea/eslint-plugin/no-identical-tests": "error",
16+
"mysticatea/eslint-plugin/no-missing-placeholders": "error",
17+
"mysticatea/eslint-plugin/no-unused-placeholders": "error",
18+
"mysticatea/eslint-plugin/no-useless-token-range": "error",
19+
"mysticatea/eslint-plugin/prefer-output-null": "error",
20+
"mysticatea/eslint-plugin/prefer-placeholders": "error",
21+
"mysticatea/eslint-plugin/prefer-replace-text": "error",
22+
"mysticatea/eslint-plugin/report-message-format": [
23+
"error",
24+
"[^a-z].*\\.$",
25+
],
26+
"mysticatea/eslint-plugin/require-meta-docs-url": "error",
27+
"mysticatea/eslint-plugin/require-meta-fixable": "error",
28+
"mysticatea/eslint-plugin/test-case-property-ordering": "error",
29+
"mysticatea/eslint-plugin/test-case-shorthand-strings": "error",
30+
},
31+
}

lib/configs/+modules.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @author Toru Nagashima
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
"use strict"
6+
7+
module.exports = {
8+
parserOptions: {
9+
sourceType: "module",
10+
},
11+
rules: {
12+
strict: "off",
13+
"mysticatea/node/no-extraneous-import": "error",
14+
"mysticatea/node/no-missing-import": "error",
15+
"mysticatea/node/no-unpublished-import": "error",
16+
},
17+
}

0 commit comments

Comments
 (0)