Skip to content

Commit

Permalink
Fix benchmark script (#7504)
Browse files Browse the repository at this point in the history
This fixes the broken benchmark script (`npm run benchmark`)
The error reason is that `rules[ruleName]` has returned a `Promise` since 16.0.0.

```sh-session
$ npm run benchmark-rule -- value-keyword-case lower
...
const rule = ruleFunc(primary, secondary, context);
             ^

TypeError: ruleFunc is not a function
...
```

Also, this changes `parserOptions.ecmaVersion` in the ESLint config to allow top-level `await`.
  • Loading branch information
ybiquitous authored Jan 30, 2024
1 parent 3de4eba commit 398d3a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
},
"prettier": "@stylelint/prettier-config",
"eslintConfig": {
"parserOptions": {
"ecmaVersion": 2023
},
"extends": [
"stylelint",
"stylelint/jest"
Expand Down
6 changes: 2 additions & 4 deletions scripts/benchmark-rule.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const { bold, yellow } = picocolors;

const [, , ruleName, ruleOptions, ruleContext] = argv;

const ruleFunc = rules[ruleName];

function printHelp() {
const script = 'node benchmark-rule.mjs';

Expand All @@ -32,7 +30,7 @@ function printHelp() {
);
}

if (!ruleFunc || !ruleOptions) {
if (!ruleName || !(ruleName in rules) || !ruleOptions) {
printHelp();
exit(-1);
}
Expand Down Expand Up @@ -65,7 +63,7 @@ const ruleSettings = normalizeRuleSettings(parsedOptions);
const [primary, secondary] = ruleSettings;
const context = ruleContext ? JSON.parse(ruleContext) : {};

const rule = ruleFunc(primary, secondary, context);
const rule = (await rules[ruleName])(primary, secondary, context);

const processor = postcss().use(rule);

Expand Down

0 comments on commit 398d3a8

Please sign in to comment.