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

Indentation rule #3427

Closed
xereda opened this issue Jun 27, 2018 · 8 comments · Fixed by #3557
Closed

Indentation rule #3427

xereda opened this issue Jun 27, 2018 · 8 comments · Fixed by #3557

Comments

@xereda
Copy link

xereda commented Jun 27, 2018

Hi,
I need help regarding a behavior in a rule.

We use sass-lint (https://github.com/sasstools/sass-lint) on some projects, but we're migrating to stylelint. In sass-lint, we use the indentation rule and it has a slightly different behavior in its validation.

Look at the illustrations:

indentation with sass-lint:
indentation_sass-lint

indentation with stylelint:
indentation_stylelint

We found that there is a difference in the validation. Sass-lint validates even the beginning of the style block, not allowing indentation in the initial part. If I indent all the contents of the block, the stylelint allows, but the sass-lint does not.

I wanted your opinion on this behavior. Does sass-lint validation make sense? Can I simulate the same validation with stylelint?

Thanks in advance for your help,

Jackson

@ntwb
Copy link
Member

ntwb commented Jun 28, 2018

I'm not why sass-lin allows the first line to be indented and that is ok /shrug

Anyways, the indentation docs here show what stylelint indents.

If you want to indent the closing brace on the last line you can do that per:

https://stylelint.io/user-guide/rules/indentation/#indentclosingbrace-truefalse

I'm also closing this as the current stylelint behaviour is intended as is.

If you believe it is a bug in stylelint then please create a new issue using the template that includes your stylelint configuration and example code for us to reproduce the issue.

@ntwb ntwb closed this as completed Jun 28, 2018
@xereda
Copy link
Author

xereda commented Jun 28, 2018

Thanks for the feedback @ntwb. Before opening the call, I have a question:

By analyzing the gif below, do you think it should have a consistency of stylelint? The stylelint is leaving indentation out of the set, just because there is no element at the top.

__indentation

The sass-lint accuses the inconsistency in these cases.

What do you think about it?

Thank you again.

@hudochenkov
Copy link
Member

Indentation you're asking about should not be a concern of stylelint, because it's HTML indentation. <style> tag could be on any indentation level. E. g.:

<!DOCTYPE html>
<html lang="en">
<head>
	<style>
		body {
			background: #fff;
		}
	</style>
</head>
<body>
</body>
</html>

Stylelint doesn't care about HTML indentation. It respects whatever indentation HTML has, but it check styles indentation.

@xereda
Copy link
Author

xereda commented Jun 28, 2018

Note that sass-lint validates the indentation also by considering the left wall of the style block.

__indentation_sass-lint

I'm just questioning this, as I'm migrating some projects with sass-lint for validation with stylelint. This non-validation can cause me problems at the time of the builds pipeline.

@ntwb and @hudochenkov Do you think I should open an issue?

@xereda
Copy link
Author

xereda commented Jun 28, 2018

@hudochenkov But, I'm working, on my projects, with SFC files from Vue.js (* .vue).

Template for vue.js files (.vue):

<template>
  <span class="test">
    { test }
  </span>
</template>

<script>
export default {
  name: 'test',
  data() {
    return {
      test: 'hello world!',
    };
  },
};
</script>

<style lang="scss" scoped>
.test {
  margin: 10px;
}
</style>

@gucong3000
Copy link
Member

gucong3000 commented Aug 17, 2018

I'm trying to solve this problem.
I've added an option baseIndentLevel, you can set this option to 0 to make the CSS indent level equal to the parent element.

"use strict";
const stylelint = require("stylelint")    // npm i stylelint/stylelint#indent_infer
stylelint.lint({
  code: `
    <style>
      a {
        display:block;
      }
    </style>`,
  codeFilename: "a.html",
  config: {
    rules: {
      indentation: [
        2,
        {
          baseIndentLevel: 0,
        }
      ]
    },
  },
  fix: true,
}).then(result => console.log(result.output));
$ node indent_test.js

    <style>
    a {
      display:block;
    }
    </style>

@gucong3000 gucong3000 reopened this Aug 17, 2018
@CodeLittlePrince
Copy link

I don't know why, baseIndentLevel doesn't work in my vue project.
image

@jeddy3
Copy link
Member

jeddy3 commented Oct 9, 2018

@CodeLittlePrince Please ensure your using the latest version of stylelint (by deleting your node_modules folder and any globally installed versions). If that doesn't fix the problem, please create a new issue (using the "Report a bug" template) so that we can better help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

6 participants