Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fnknzzz committed Mar 30, 2018
2 parents a2442bf + 9e394b8 commit 2429205
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/rules/first.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = {
const removeFixers = sortNodes.map(function (_errorInfo) {
return fixer.removeRange(_errorInfo.range)
})
, range = [0, removeFixers[removeFixers.length - 1].range[1]]
let insertSourceCode = sortNodes.map(function (_errorInfo) {
const nodeSourceCode = String.prototype.slice.apply(
originSourceCode, _errorInfo.range
Expand All @@ -99,14 +100,21 @@ module.exports = {
return nodeSourceCode
}).join('')
, insertFixer = null
, replaceSourceCode = ''
if (!lastLegalImp) {
insertSourceCode =
insertSourceCode.trim() + insertSourceCode.match(/^(\s+)/)[0]
}
insertFixer = lastLegalImp ?
fixer.insertTextAfter(lastLegalImp, insertSourceCode) :
fixer.insertTextBefore(body[0], insertSourceCode)
return removeFixers.concat([insertFixer])
const fixers = [insertFixer].concat(removeFixers)
fixers.forEach(function (computedFixer, i) {
replaceSourceCode += (originSourceCode.slice(
fixers[i - 1] ? fixers[i - 1].range[1] : 0, computedFixer.range[0]
) + computedFixer.text)
})
return fixer.replaceTextRange(range, replaceSourceCode)
}
}
context.report(infos)
Expand Down
10 changes: 0 additions & 10 deletions tests/src/rules/first.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ ruleTester.run('first', rule, {
import { y } from 'bar';\
'use directive';"
})
, test({ code: "var foo = bar;\
import { x } from './foo';\
import { y } from './bar';\
import { z } from './baz';"
, errors: 3
, output: "import { x } from './foo';\
import { y } from './bar';\
import { z } from './baz';\
var foo = bar;"
})
, test({ code: "var a = 1;\
import { y } from './bar';\
if (true) { x() };\
Expand Down

0 comments on commit 2429205

Please sign in to comment.