Skip to content

WIP: Add html-indent rule. #87

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

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 41 additions & 0 deletions docs/rules/html-indent.md
Original file line number Diff line number Diff line change
@@ -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
<template>
<div>
</div>
</template>
```

Examples of **correct** code for this rule:

```html
<template>
<div>
</div>
</template>
```

## :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']
```
53 changes: 53 additions & 0 deletions lib/rules/html-indent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @fileoverview Enforce consistent indentation in html template
* @author Armano
*/
'use strict'

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------

function create (context) {
// variables should be defined here

// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------

// any helper functions should go here or else delete this section

// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------

return {
// give me methods
}
}

module.exports = {
meta: {
docs: {
description: 'Enforce consistent indentation in html template',
category: 'Stylistic Issues',
recommended: false
},
fixable: null, // or "code" or "whitespace"
schema: [
{
oneOf: [
{
enum: ['tab']
},
{
type: 'integer',
minimum: 0
}
]
}
]
},

create
}
34 changes: 34 additions & 0 deletions tests/lib/rules/html-indent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @fileoverview Enforce consistent indentation in html template
* @author Armano
*/
'use strict'

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/html-indent')
const RuleTester = require('eslint').RuleTester

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester()
ruleTester.run('html-indent', rule, {

valid: [
// give me some code that won't trigger a warning
],

invalid: [
{
code: '',
errors: [{
message: 'Fill me in.',
type: 'Me too'
}]
}
]
})