Skip to content

Update: use multiple-autofixes. #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions lib/rules/attributes-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,10 @@ function create (context) {
const attributes = node.parent.attributes
const shiftAttrs = attributes.slice(attributes.indexOf(previousNode), attributes.indexOf(node) + 1)

// If we can upgrade requirements to `eslint@>4.1.0`, this code can be replaced by:
// return shiftAttrs.map((attr, i) => {
// const text = attr === previousNode ? sourceCode.getText(node) : sourceCode.getText(shiftAttrs[i - 1])
// return fixer.replaceText(attr, text)
// })
const replaceDataList = shiftAttrs.map((attr, i) => {
return shiftAttrs.map((attr, i) => {
const text = attr === previousNode ? sourceCode.getText(node) : sourceCode.getText(shiftAttrs[i - 1])
return {
range: attr.range,
text
}
return fixer.replaceText(attr, text)
})
const replaceRange = [previousNode.range[0], node.range[1]]
let text = sourceCode.text.slice(replaceRange[0], replaceRange[1])
replaceDataList.reverse().forEach((data) => {
const textRange = data.range.map(r => r - replaceRange[0])
text = text.slice(0, textRange[0]) + data.text + text.slice(textRange[1], text.length)
})
return fixer.replaceTextRange(replaceRange, text)
}
})
}
Expand Down
12 changes: 4 additions & 8 deletions lib/rules/component-name-in-template-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ module.exports = {
const caseType = allowedCaseOptions.indexOf(caseOption) !== -1 ? caseOption : defaultCase
const ignores = options.ignores || []
const tokens = context.parserServices.getTemplateBodyTokenStore && context.parserServices.getTemplateBodyTokenStore()
const sourceCode = context.getSourceCode()

let hasInvalidEOF = false

Expand Down Expand Up @@ -88,13 +87,10 @@ module.exports = {
return fixer.replaceText(open, `<${casingName}`)
}
const endTagOpen = tokens.getFirstToken(endTag)
// If we can upgrade requirements to `eslint@>4.1.0`, this code can be replaced by:
// return [
// fixer.replaceText(open, `<${casingName}`),
// fixer.replaceText(endTagOpen, `</${casingName}`)
// ]
const code = `<${casingName}${sourceCode.text.slice(open.range[1], endTagOpen.range[0])}</${casingName}`
return fixer.replaceTextRange([open.range[0], endTagOpen.range[1]], code)
return [
fixer.replaceText(open, `<${casingName}`),
fixer.replaceText(endTagOpen, `</${casingName}`)
]
}
})
}
Expand Down
14 changes: 4 additions & 10 deletions lib/rules/no-shared-component-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,10 @@ module.exports = {
fix (fixer) {
const tokens = getFirstAndLastTokens(p.value, sourceCode)

// If we can upgrade requirements to `eslint@>4.1.0`, this code can be replaced by:
// return [
// fixer.insertTextBefore(tokens.first, 'function() {\nreturn '),
// fixer.insertTextAfter(tokens.last, ';\n}')
// ]
// See: https://eslint.org/blog/2017/06/eslint-v4.1.0-released#applying-multiple-autofixes-simultaneously
const range = [tokens.first.range[0], tokens.last.range[1]]
const valueText = sourceCode.text.slice(range[0], range[1])
const replacement = `function() {\nreturn ${valueText};\n}`
return fixer.replaceTextRange(range, replacement)
return [
fixer.insertTextBefore(tokens.first, 'function() {\nreturn '),
fixer.insertTextAfter(tokens.last, ';\n}')
]
}
})
})
Expand Down