Skip to content

The function-disallowed-list rule does not report an error in the return expression of an scss function #1151

@sharikovvladislav

Description

@sharikovvladislav

What minimal example or steps are needed to reproduce the bug?

@use "sass:math"
@function get-random-value() {
  @return math.random(100.5);
}
.a { margin-left: get-random-value(); }

^^ this does not work

However, the following works:

@use "sass:math"
@function get-random-value() {
  $v: math.random(100.5);
  @return $v;
}
.a { margin-left: get-random-value(); }

What minimal configuration is needed to reproduce the bug?

{
  "rules": {
    "scss/function-disallowed-list": [["random"]],
  }
}

How did you run Stylelint?

stylelint app/**/*.scss --config .stylelintrc.json

Which Stylelint-related dependencies are you using?

"stylelint": "16.8.1",
"stylelint-config-standard": "36.0.1",
"stylelint-order": "6.0.4",
"stylelint-prettier": "5.0.3",
"stylelint-scss": "6.5.0",

What did you expect to happen?

I expect that the scss/function-disallowed-list will be violated because of the config.

What actually happened?

The error was not reported when the code with a violation is the return expression of a function.

Do you have a proposal to fix the bug?

Here is the reproduction. Add the following test to the src/rules/function-disallowed-list/__tests__/index.js spec file:

testRule({
  ruleName,
  config: ["random"],
  customSyntax: "postcss-scss",

  reject: [
    {
      code: `
        @use "sass:math"
        @function get-random-value() {
          @return math.random(100.5);
        }
        .a { margin-left: get-random-value(); }
      `,
      message: messages.rejected("random"),
      description: "Math library function, not allowed."
    }
  ],
});

Also, it can be reproduced in this online demo by @ybiquitous (mentioned here stylelint/stylelint#8565 (comment))

It seems the stylelint walks only declarations and skips the return expressions because of the root.walkDecls specifics.

I wrongly created similar issue in the stylelint repo: stylelint/stylelint#8565. Moving it here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions