最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use TIMING=1 eslint to measure rule Performance in Windows OS - Stack Overflow

programmeradmin5浏览0评论

In ESLint official website, there is a paragraph, called Per-rule Performance.

It states that

"setting the TIMING environment variable will trigger the display, upon linting pletion, of the ten longest-running rules, along with their individual running time and relative performance impact as a percentage of total rule processing time".

$ TIMING=1 eslint lib
Rule                    | Time (ms) | Relative
:-----------------------|----------:|--------:
no-multi-spaces         |    52.472 |     6.1%
camelcase               |    48.684 |     5.7%
no-irregular-whitespace |    43.847 |     5.1%
valid-jsdoc             |    40.346 |     4.7%
handle-callback-err     |    39.153 |     4.6%
space-infix-ops         |    35.444 |     4.1%
no-undefined            |    25.693 |     3.0%
no-shadow               |    22.759 |     2.7%
no-empty-class          |    21.976 |     2.6%
semi                    |    19.359 |     2.3%

However, when I add

"lint-js": "TIMING=1 eslint --ext .js,.jsx,.ts,.tsx src/js --cache --cache-strategy metadata"

in the "scripts" in package.json and run it with

npm run lint-js

in my Windows OS, I get

'TIMING' is not recognized as an internal or external mand,
operable program or batch file.

How to run TIMING=1 with eslint in Windows OS?

In ESLint official website, there is a paragraph, called Per-rule Performance.

It states that

"setting the TIMING environment variable will trigger the display, upon linting pletion, of the ten longest-running rules, along with their individual running time and relative performance impact as a percentage of total rule processing time".

$ TIMING=1 eslint lib
Rule                    | Time (ms) | Relative
:-----------------------|----------:|--------:
no-multi-spaces         |    52.472 |     6.1%
camelcase               |    48.684 |     5.7%
no-irregular-whitespace |    43.847 |     5.1%
valid-jsdoc             |    40.346 |     4.7%
handle-callback-err     |    39.153 |     4.6%
space-infix-ops         |    35.444 |     4.1%
no-undefined            |    25.693 |     3.0%
no-shadow               |    22.759 |     2.7%
no-empty-class          |    21.976 |     2.6%
semi                    |    19.359 |     2.3%

However, when I add

"lint-js": "TIMING=1 eslint --ext .js,.jsx,.ts,.tsx src/js --cache --cache-strategy metadata"

in the "scripts" in package.json and run it with

npm run lint-js

in my Windows OS, I get

'TIMING' is not recognized as an internal or external mand,
operable program or batch file.

How to run TIMING=1 with eslint in Windows OS?

Share Improve this question edited Apr 18, 2022 at 9:59 obelisk0114 asked Apr 18, 2022 at 6:35 obelisk0114obelisk0114 3436 silver badges15 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 7

After some researching, I found a simple way to solve cross-platform issue.

"lint-js": "export TIMING=1 || set TIMING=1&& eslint --ext .js,.jsx,.ts,.tsx src/js --cache --cache-strategy metadata"

The vertical bars are needed as otherwise Windows would crash on the unrecognized export.

Reference link: https://stackoverflow./a/36373133/13230147

In Windows environment variables should be set using the set mand.

Try the following from the mand line:

set TIMING=1
npx eslint --ext .js,.jsx,.ts,.tsx src/js --cache --cache-strategy metadata

You have two options: work with the set mand or use an external tool like cross-env:

Using set (Windows only)

"lint-js": "set TIMING=1 && eslint --ext .js,.jsx,.ts,.tsx src/js --cache --cache-strategy metadata"

Using cross-env

Install with:

npm install -D cross-env

Then change the script mand to:

"lint-js": "cross-env TIMING=1 eslint --ext .js,.jsx,.ts,.tsx src/js --cache --cache-strategy metadata"

I had the same problem using Windows, my work team use Mac you can try using https://www.npmjs./package/cross-env, that worked for me.

"lint": "cross-env TIMING=1 next lint",

use set TIMING=1 in cmd or $env:TIMING=1 in powershell

发布评论

评论列表(0)

  1. 暂无评论