eslint-plugin-wyze
Advanced tools
Comparing version 3.2.0 to 3.2.1
## Change Log | ||
### [v3.2.1](https://github.com/wyze/eslint-plugin-wyze/releases/tag/v3.2.1) (2017-05-06) | ||
* [[`117195538d`](https://github.com/wyze/eslint-plugin-wyze/commit/117195538d)] - Use original delimiter when fixing specifiers (#11) (Justin Anastos) | ||
* [[`eb4054d07e`](https://github.com/wyze/eslint-plugin-wyze/commit/eb4054d07e)] - Remove snapshot tests and use RuleTester for output validation (Neil Kistner) | ||
### [v3.2.0](https://github.com/wyze/eslint-plugin-wyze/releases/tag/v3.2.0) (2017-03-26) | ||
@@ -4,0 +9,0 @@ |
@@ -0,1 +1,3 @@ | ||
/* eslint-disable wyze/max-file-length */ | ||
'use strict' | ||
@@ -43,2 +45,40 @@ | ||
const getRootNode = node => { | ||
let testNode = node | ||
while ( testNode ) { | ||
if ( testNode.type === 'Program' ) { | ||
return testNode | ||
} | ||
testNode = testNode.parent | ||
} | ||
throw new Error('Could not get Program node') | ||
} | ||
const getContentBetweenSpecifiers = ( context, parent, nodeOrTokenA, nodeOrTokenB ) => { | ||
const sourceCode = context.getSourceCode() | ||
const text = sourceCode.getText(parent) | ||
const start = nodeOrTokenA.end - parent.start | ||
const length = nodeOrTokenB.start - nodeOrTokenA.end | ||
const contentBetween = text.substr(start, length) | ||
return contentBetween | ||
} | ||
const getContentBetweenDeclarations = ( context, nodeOrTokenA, nodeOrTokenB ) => { | ||
const sourceCode = context.getSourceCode() | ||
const rootNode = getRootNode(nodeOrTokenA) | ||
const text = sourceCode.getText(rootNode) | ||
const start = nodeOrTokenA.end - nodeOrTokenA.start | ||
const length = nodeOrTokenB.start - nodeOrTokenA.end | ||
const contentBetween = text.substr(start, length) | ||
return contentBetween | ||
} | ||
const checkSpecifiers = ( context, getText, node, ignoreMemberSort, ignoreCase ) => { | ||
@@ -48,4 +88,11 @@ if ( !ignoreMemberSort && node.specifiers.length > 1 ) { | ||
let pSpecifierName | ||
const makeFix = cSpecifier => fixer => | ||
fixer.replaceTextRange( | ||
const makeFix = cSpecifier => fixer => { | ||
const delimiter = getContentBetweenSpecifiers( | ||
context, | ||
node, | ||
pSpecifier.local, | ||
cSpecifier.local | ||
) | ||
return fixer.replaceTextRange( | ||
[ | ||
@@ -55,4 +102,5 @@ pSpecifier.range[0], | ||
], | ||
`${getText(cSpecifier)}, ${getText(pSpecifier)}` | ||
`${getText(cSpecifier)}${delimiter}${getText(pSpecifier)}` | ||
) | ||
} | ||
@@ -155,4 +203,7 @@ // eslint-disable-next-line no-plusplus | ||
const fix = fixer => | ||
fixer.replaceTextRange( | ||
const fix = fixer => { | ||
const delimiter = getContentBetweenDeclarations(context, pNode, node) | ||
return fixer.replaceTextRange( | ||
[ | ||
@@ -162,4 +213,5 @@ pNode.range[0], | ||
], | ||
`${getText(node)}\n${getText(pNode)}` | ||
`${getText(node)}${delimiter}${getText(pNode)}` | ||
) | ||
} | ||
@@ -166,0 +218,0 @@ // When the current declaration uses a different member syntax, |
{ | ||
"name": "eslint-plugin-wyze", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "My personal ESLint rules.", | ||
@@ -87,13 +87,3 @@ "license": "MIT", | ||
} | ||
}, | ||
"jest": { | ||
"snapshotSerializers": [ | ||
"<rootDir>/lib/rules/__tests__/serializers/serializer-eslint-filepath" | ||
], | ||
"testPathIgnorePatterns": [ | ||
"/fixtures/", | ||
"/node_modules/", | ||
"/serializers/" | ||
] | ||
} | ||
} |
@@ -87,10 +87,6 @@ # eslint-plugin-wyze | ||
### [v3.2.0](https://github.com/wyze/eslint-plugin-wyze/releases/tag/v3.2.0) (2017-03-26) | ||
### [v3.2.1](https://github.com/wyze/eslint-plugin-wyze/releases/tag/v3.2.1) (2017-05-06) | ||
* [[`d73bc26394`](https://github.com/wyze/eslint-plugin-wyze/commit/d73bc26394)] - Add filepath serializer to Jest to make snapshots valid on Travis (Neil Kistner) | ||
* [[`72c04f70ac`](https://github.com/wyze/eslint-plugin-wyze/commit/72c04f70ac)] - Upgrade dependencies (Neil Kistner) | ||
* [[`9969920a30`](https://github.com/wyze/eslint-plugin-wyze/commit/9969920a30)] - Add snapshot tests for `sort-import` rule fixes (Neil Kistner) | ||
* [[`ace0a759ed`](https://github.com/wyze/eslint-plugin-wyze/commit/ace0a759ed)] - Add snapshot tests for `--fix` tests (Neil Kistner) | ||
* [[`94c9adf380`](https://github.com/wyze/eslint-plugin-wyze/commit/94c9adf380)] - Switch to Jest for testing (Neil Kistner) | ||
* [[`8a63051086`](https://github.com/wyze/eslint-plugin-wyze/commit/8a63051086)] - Make sort-imports fix the sort order (#10) (Justin Anastos) | ||
* [[`117195538d`](https://github.com/wyze/eslint-plugin-wyze/commit/117195538d)] - Use original delimiter when fixing specifiers (#11) (Justin Anastos) | ||
* [[`eb4054d07e`](https://github.com/wyze/eslint-plugin-wyze/commit/eb4054d07e)] - Remove snapshot tests and use RuleTester for output validation (Neil Kistner) | ||
@@ -97,0 +93,0 @@ ## License |
39296
717
104