Skip to content
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

[Update] Make vue/max-attributes-per-line fixable #380

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[fix] don't handle indentation
ota-meshi committed Feb 6, 2018
commit 50b34eccf72045ffe507fdd2332c820b23038775
31 changes: 1 addition & 30 deletions lib/rules/max-attributes-per-line.js
Original file line number Diff line number Diff line change
@@ -9,8 +9,6 @@
// ------------------------------------------------------------------------------
const utils = require('../utils')

const LT_CHAR = /[\r\n\u2028\u2029]/

module.exports = {
meta: {
docs: {
@@ -72,7 +70,6 @@ module.exports = {
const multilineMaximum = configuration.multiline
const singlelinemMaximum = configuration.singleline
const canHaveFirstLine = configuration.allowFirstLine
const sourceCode = context.getSourceCode()

return utils.defineTemplateBodyVisitor(context, {
'VStartTag' (node) {
@@ -140,18 +137,7 @@ module.exports = {
data: {
propName: prop.key.name
},
fix: i === 0 ? (fixer) => {
let indent = getIndentText(prop)
if (prop.loc.start.line === node.loc.start.line) {
const last = indent[indent.length - 1]
if (indent[indent.length - 1] === '\t') {
indent += '\t'
} else {
indent += last + last
}
}
return fixer.insertTextBefore(prop, `\n${indent}`)
} : undefined
fix: i === 0 ? (fixer) => fixer.insertTextBefore(prop, '\n') : undefined
})
})
}
@@ -170,20 +156,5 @@ module.exports = {

return propsPerLine
}

function getIndentText (node) {
const text = sourceCode.text
let indentStart = node.range[0] - 1
while (indentStart >= 0 && !LT_CHAR.test(text[indentStart])) {
indentStart -= 1
}
let indentEnd = indentStart + 1

while (!text[indentEnd].trim()) {
indentEnd += 1
}

return text.slice(indentStart + 1, indentEnd)
}
}
}