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

Unexpected Node API output when any rule contains disableFix: true #6542

Closed
adrianjost opened this issue Dec 23, 2022 · 3 comments · Fixed by #6543
Closed

Unexpected Node API output when any rule contains disableFix: true #6542

adrianjost opened this issue Dec 23, 2022 · 3 comments · Fixed by #6543
Labels
status: wip is being worked on by someone type: bug a problem with a feature or rule

Comments

@adrianjost
Copy link
Contributor

adrianjost commented Dec 23, 2022

What steps are needed to reproduce the bug?

disableFix: true in any stylelint rule breaks the output of the node api if the fix: true option is set.
If this configuration is provided for any rule, instead of containing the fixed code, the regular output that would have been shown without the fix: true flag is returned.
A symptom of this issue is that the VSCode eidtor integration can not autofix any issues.

Example Script

import * as stylelint from "stylelint";

async function lint(cssContent: string): Promise<void> {
  try {
    const lintResult = await stylelint.lint({
      code: cssContent,
      fix: true,
    });
    console.log(lintResult.output);
  } catch (error) {
    console.error(error);
  }
}
lint(`.border-top-default {
  border-top: 1px solid red;
  margin: 0;
}`);

And configuration:
Example stylelint config:
used packages: stylelint-order, stylelint-scss, stylelint-declaration-strict-value.

module.exports = {
  customSyntax: "postcss-scss",
  plugins: ["stylelint-declaration-strict-value", "stylelint-order"],
  rules: {
    "order/properties-order": [["margin", "border"], { unspecified: "bottom" }],
    "scale-unlimited/declaration-strict-value": [
      "/border/",
      { disableFix: true }, // this one breaks the autofix
    ],
  },
};

What Stylelint configuration is needed to reproduce the bug?

module.exports = {
  plugins: ["stylelint-declaration-strict-value", "stylelint-order"],
  rules: {
    "order/properties-order": [["margin", "border"], { unspecified: "bottom" }],
    "scale-unlimited/declaration-strict-value": [
      "/border/",
      { disableFix: true }, // this one breaks the autofix
    ],
  },
};

How did you run Stylelint?

NodeJS script, provided in steps to reproduce bug

Which version of Stylelint are you using?

14.15.0

What did you expect to happen?

I expect the intResult.output to contain the fixed CSS

.border-top-default {
  margin: 0;
  border-top: : 1px solid red;
}

What actually happened?

But as soon as disableFix: true is set, I get the following result:

[{
  "source": "<input css rPadxH>",
  "deprecations": [],
  "invalidOptionWarnings": [],
  "parseErrors": [],
  "errored": false,
  "warnings": []
}]

which is similar to the result that I get when I remvoe the fix: true option from the node script.

[{
  "source": "<input css qETqql>",
  "deprecations": [],
  "invalidOptionWarnings": [],
  "parseErrors": [],
  "errored": true,
  "warnings": [
    {
      "line": 3,
      "column": 5,
      "endLine": 3,
      "endColumn": 15,
      "rule": "order/properties-order",
      "severity": "error",
      "text": "Expected \"margin\" to come before \"border-top\" (order/properties-order)"
    }
  ]
}]

Does the bug relate to non-standard syntax?

I don't think so

Proposal to fix the bug

Not yet, will try to look into it.

@adrianjost
Copy link
Contributor Author

Related Issue in the VSCode editor plugin: stylelint/vscode-stylelint#369

@adrianjost
Copy link
Contributor Author

adrianjost commented Dec 23, 2022

I suspect it is because of https://github.com/stylelint/stylelint/blob/main/lib/standalone.js#L146. Removing the last condition fixes the issue but I'm not sure about any other consequences.

adrianjost added a commit to adrianjost/stylelint that referenced this issue Dec 23, 2022
…ue` stylelint#6542

fixes stylelint#6542 and bv that should also fix stylelint/vscode-stylelint#369

Issue: The API did not return the fixed css in `output` if any rule contained `ruleDisableFix`.

I have removed the `ruleDisableFix` code, because it did not affect the code fixing itself and was assumingly wrongly used to change the content format of `output`.
I have adjusted some tests to adapt to the changed behaviour and extended the test conditions to check that the returned code has the correct fixes applied.

Issue was introduced in stylelint#5460
@ybiquitous ybiquitous added status: wip is being worked on by someone type: bug a problem with a feature or rule labels Dec 28, 2022
@ybiquitous
Copy link
Member

@adrianjost Thanks for firing the detailed report and creating the pull request. I can reproduce the bug. 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wip is being worked on by someone type: bug a problem with a feature or rule
2 participants