diff --git a/docs/rules/html-indent.md b/docs/rules/html-indent.md new file mode 100644 index 000000000..9786c3b13 --- /dev/null +++ b/docs/rules/html-indent.md @@ -0,0 +1,41 @@ +# Enforce consistent indentation in html template (html-indent) + +Please describe the origin of the rule here. + +## :book: Rule Details + +This rule aims to... + +Examples of **incorrect** code for this rule: + +```html + +``` + +Examples of **correct** code for this rule: + +```html + +``` + +## :wrench: Options + +This rule has a mixed option: + +For example, for 2-space indentation: + +``` +vue/html-indent: [2, 2] +``` + +Or for tabbed indentation: + +``` +vue/html-indent: [2, 'tab'] +``` diff --git a/lib/rules/html-indent.js b/lib/rules/html-indent.js new file mode 100644 index 000000000..265edb59a --- /dev/null +++ b/lib/rules/html-indent.js @@ -0,0 +1,133 @@ +/** + * @fileoverview Enforce consistent indentation in html template + * @author Armano + */ +'use strict' + +// ------------------------------------------------------------------------------ +// Requirements +// ------------------------------------------------------------------------------ + +const utils = require('../utils') + +const REGEXP_VTEXT = /([^\r\n]*)([\r\n]*)([\s\t]*)$/g // Get last text + caret + whitespaces + +// ------------------------------------------------------------------------------ +// Rule Definition +// ------------------------------------------------------------------------------ + +function create (context) { + const sourceCode = context.getSourceCode() + const options = context.options[0] || 2 + const indentCount = options === 'tab' ? 1 : options + const indentType = options === 'tab' ? 'tab' : 'space' + const tagIndent = options === 'tab' ? '\t' : ' '.repeat(options) + const attrIndent = tagIndent // TODO: add way to configure this + let currentIndent = -1 // Start at -1 for