-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f41c293
Showing
8 changed files
with
2,121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const rulesDirPlugin = require('eslint-plugin-rulesdir') | ||
|
||
rulesDirPlugin.RULES_DIR = 'lib/rules' | ||
|
||
module.exports = { | ||
extends: [ | ||
'plugin:@kusotenpa/base', | ||
], | ||
plugins: [ 'rulesdir' ], | ||
env: { | ||
es6: true, | ||
node: true, | ||
}, | ||
rules: { | ||
'rulesdir/object-property-newline': 2, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
### https://raw.github.com/github/gitignore/5d896f6791c4257b74696714c66b2530b8d95a51/Node.gitignore | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# eslint-plugin-destructuring-newline | ||
Enforce placing destructuring properties on separate lines. | ||
|
||
## Installation | ||
``` | ||
$ npm install --save-dev eslint eslint-plugin-destructuring-newline | ||
``` | ||
|
||
## Usage | ||
In your `.eslintrc` | ||
``` | ||
{ | ||
"plugins": [ | ||
"destructuring-newline" | ||
], | ||
"rules": { | ||
"destructuring-newline/object-property-newline": 2 | ||
} | ||
} | ||
``` | ||
|
||
## Rule Details | ||
```js | ||
// bad | ||
const { foo, bar } = obj3 | ||
|
||
// good | ||
const { foo } = obj1 | ||
const { | ||
foo, | ||
bar, | ||
} = obj2 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
rules: { | ||
'object-property-newline': require('./rules/object-property-newline'), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
meta: { | ||
type: 'layout', | ||
messages: { | ||
propertiesOnNewline: 'Destructuring properties must go on a new line.', | ||
}, | ||
fixable: 'whitespace', | ||
}, | ||
create: context => { | ||
const sourceCode = context.getSourceCode() | ||
|
||
return { | ||
ObjectPattern(node) { | ||
if (node.properties.length <= 1) { | ||
return | ||
} | ||
|
||
for (let i = 1; i < node.properties.length; i++) { | ||
const lastPrev = sourceCode.getLastToken(node.properties[ i - 1 ]) | ||
const firstCurrent = sourceCode.getFirstToken(node.properties[ i ]) | ||
|
||
if (lastPrev.loc.end.line === firstCurrent.loc.start.line) { | ||
context.report({ | ||
node, | ||
loc: firstCurrent.loc, | ||
messageId: 'propertiesOnNewline', | ||
fix(fixer) { | ||
const comma = sourceCode.getTokenBefore(firstCurrent) | ||
const afterComma = [ comma.range[ 1 ], firstCurrent.range[ 0 ] ] | ||
|
||
return fixer.replaceTextRange(afterComma, '\n') | ||
}, | ||
}) | ||
} | ||
} | ||
}, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "eslint-plugin-destructuring-newline", | ||
"version": "0.0.1", | ||
"description": "Enforce placing destructuring properties on separate lines", | ||
"main": "lib/index.js", | ||
"license": "MIT", | ||
"keywords": [ | ||
"eslint", | ||
"eslint-plugin", | ||
"destructuring", | ||
"newline" | ||
], | ||
"scripts": { | ||
"test": "mocha test/**/*.js --reporter spec" | ||
}, | ||
"devDependencies": { | ||
"@kusotenpa/eslint-plugin": "1.1.0", | ||
"eslint": "7.6.0", | ||
"eslint-plugin-rulesdir": "0.1.0", | ||
"mocha": "8.1.1" | ||
}, | ||
"peerDependencies": { | ||
"eslint": ">=7.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
|
||
const rule = require('../../lib/rules/object-property-newline') | ||
|
||
const tester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 6, | ||
}, | ||
}) | ||
|
||
tester.run('object-property-newline', rule, { | ||
valid: [ | ||
{ | ||
code: 'var {a,\nb} = obj;', | ||
}, | ||
{ | ||
code: 'var {a} = obj;', | ||
}, | ||
{ | ||
code: 'var {\na\n} = obj;', | ||
}, | ||
{ | ||
code: 'function foo({a,\nb}){};', | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: 'var {a,b} = obj;', | ||
output: 'var {a,\nb} = obj;', | ||
errors: [ { | ||
messageId: 'propertiesOnNewline', | ||
} ], | ||
}, | ||
{ | ||
code: 'var {a,b,c} = obj;', | ||
output: 'var {a,\nb,\nc} = obj;', | ||
errors: [ | ||
{ | ||
messageId: 'propertiesOnNewline', | ||
}, | ||
{ | ||
messageId: 'propertiesOnNewline', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'var {\na,b} = obj;', | ||
output: 'var {\na,\nb} = obj;', | ||
errors: [ | ||
{ | ||
messageId: 'propertiesOnNewline', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'function foo({a,b}){};', | ||
output: 'function foo({a,\nb}){};', | ||
errors: [ | ||
{ | ||
messageId: 'propertiesOnNewline', | ||
}, | ||
], | ||
}, | ||
], | ||
}) |
Oops, something went wrong.