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

Add baseIndentLevel to indentation #3557

Merged
merged 1 commit into from
Sep 6, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/rules/indentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ a {

## Optional secondary options

### `baseIndentLevel: int|"auto"`

By default, the indent level of the CSS code block in non-CSS-like files is determined by the shortest indent of non-empty line. The setting `baseIndentLevel` allows you to define a relative indent level based on CSS code block opening or closing line.

For example, with `[ 2, { baseIndentLevel: 1 } ]`, CSS should be indented 1 levels higher than `<style>` tag:

```html
<!DOCTYPE html>
<html lang="en">
<head>
<style>
a {
display: block;
}
</style>
</head>
</html>
```

### `indentInsideParens: "twice"|"once-at-root-twice-in-block"`

By default, *one extra* indentation (of your specified type) is expected after newlines inside parentheses, and the closing parenthesis is expected to have no extra indentation.
Expand Down
225 changes: 216 additions & 9 deletions lib/rules/indentation/__tests__/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ a {
\tdisplay:block;
}
</style>`
},
{
code: `
<style>a {
\tdisplay:block;
}
</style>`
},
{
code: '<a style="display:block; color:red;"></a>'
}
],

Expand All @@ -48,6 +58,23 @@ a {
},
{
code: `
<style>
a {
display:block;
}
</style>`,
fixed: `
<style>
\ta {
\t\tdisplay:block;
\t}
</style>`,
message: messages.expected("1 tab"),
line: 3,
column: 3
},
{
code: `
<style>
a {
display:block;
Expand Down Expand Up @@ -83,23 +110,203 @@ a {
{
code: `
\t<style>
\t a {
\t display:block;
\t }
\t</style>
a {
display:block;
}
b {
display:block;
}
\t</style>`,
fixed: `
\t<style>
\ta {
\t\tdisplay:block;
\t}
\tb {
\t\tdisplay:block;
\t}
\t</style>`,
message: messages.expected("1 tab"),
line: 3,
column: 5
}
]
});

testRule(rule, {
ruleName,
config: [2],
syntax: "html",
fix: true,

accept: [
{
code: `
<style>
a {
display:block;
}
</style>`
},
{
code: `
<style>
a {
display:block;
}
</style>`
},
{
code: `
<style>a {
display:block;
}
</style>`
}
],
reject: [
{
code: `
<style>a {
display:block;
}
</style>`,
fixed: `
<style>a {
display:block;
}
</style>`,
message: messages.expected("2 spaces"),
line: 3,
column: 2
}
]
});

testRule(rule, {
ruleName,
config: [
"tab",
{
baseIndentLevel: 1
}
],
syntax: "html",
fix: true,

accept: [
{
code: `
<style>
\ta {
\t\tdisplay:block;
\t}
</style>`
},
{
code: `
\t<style>
\t\ta {
\t\t\tdisplay:block;
\t\t}
\t</style>`
}
],
reject: [
{
code: `
<style>
a {
\tdisplay:block;
}
</style>`,
fixed: `
<style>
\ta {
\t\tdisplay:block;
\t}
</style>`,
message: messages.expected("1 tab"),
line: 3,
column: 1
},
{
code: `
\t<style>
\t b {
\t display:block;
\t }
\ta {
\t\tdisplay:block;
\t}
\t</style>`,
fixed: `
\t<style>
\t\ta {
\t\t\tdisplay:block;
\t\t}
\t</style>`,
message: messages.expected("2 tabs"),
line: 3,
column: 2
}
]
});

testRule(rule, {
ruleName,
config: [
"tab",
{
baseIndentLevel: 0
}
],
syntax: "html",
fix: true,

accept: [
{
code: `
<style>
a {
\tdisplay:block;
}
</style>`
},
{
code: `
\t<style>
\ta {
\t\tdisplay:block;
\t}
\t</style>`
}
],
reject: [
{
code: `
<style>
\ta {
\t\tdisplay:block;
\t}
\t</style>
</style>`,
fixed: `
<style>
a {
\tdisplay:block;
}
</style>`,
message: messages.expected("0 tabs"),
line: 3,
column: 2
},
{
code: `
\t<style>
\tb {
\t\ta {
\t\t\tdisplay:block;
\t\t}
\t</style>`,
fixed: `
\t<style>
\ta {
\t\tdisplay:block;
\t}
\t</style>`,
Expand Down