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

chore: improve/decouple eslint and tsc 'npm run' commands #26704

Merged
merged 7 commits into from
Jan 24, 2024

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented Jan 20, 2024

SUMMARY

I was having issues running just tsc or eslint using our npm run scripts in package.json, because of the way they were set up. Comment line-per-line in the PR here.

  1. main goal of the PR: improve npm run commands
  2. secondary mission: break down some linting CI steps into sub-step (one for eslint, and one for tsc), allowing better time accounting and error/warning attribution

@@ -37,7 +37,7 @@
"src/setup/*"
],
"scripts": {
"_lint": "eslint --ignore-path=.eslintignore --ext .js,.jsx,.ts,tsx .",
"eslint": "eslint --ignore-path=.eslintignore --ext .js,.jsx,.ts,tsx",
Copy link
Member Author

@mistercrunch mistercrunch Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

killing _lint with a simple eslint command with the parameters that should always be used, but importantly removing that . at the end that prevents using this construct to run a specific folder of file. Since _lint is implicitely "private" given the underscore, I thought is was ok to just remove it.

@@ -51,8 +51,8 @@
"dev": "webpack --mode=development --color --watch",
"dev-server": "cross-env NODE_ENV=development BABEL_ENV=development node --max_old_space_size=4096 ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --mode=development",
"format": "npm run _prettier -- --write",
"lint": "npm run _lint && npm run type",
"lint-fix": "npm run _lint -- --fix && npm run type",
"lint": "npm run eslint -- . && npm run type",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maintaining backward compatibility, though I think we should deprecate eventually as it's unclear that you're running two commands here, and arguably tsc isn't really linting.

"lint": "npm run _lint && npm run type",
"lint-fix": "npm run _lint -- --fix && npm run type",
"lint": "npm run eslint -- . && npm run type",
"lint-fix": "npm run eslint -- . --fix",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, maintaining backward compat

@pull-request-size pull-request-size bot added size/M and removed size/S labels Jan 20, 2024
@@ -36,11 +36,20 @@ jobs:
uses: ./.github/actions/cached-dependencies
with:
run: npm-install
- name: lint
- name: eslint
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

breaking down the steps in CI makes it more clear where the output is coming from, and gets timing info on the different steps. Helping understand the time it takes for each step

Copy link

codecov bot commented Jan 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e86d4d3) 69.48% compared to head (b2215e4) 69.48%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #26704   +/-   ##
=======================================
  Coverage   69.48%   69.48%           
=======================================
  Files        1894     1894           
  Lines       74138    74138           
  Branches     8243     8243           
=======================================
  Hits        51515    51515           
  Misses      20554    20554           
  Partials     2069     2069           
Flag Coverage Δ
javascript 56.86% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -20,6 +20,7 @@ cd "$(dirname "$0")"
npm --version
node --version
time npm ci
time npm run lint
time npm run eslint -- .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is -- . needed here and not for TypeScript?

Copy link
Member Author

@mistercrunch mistercrunch Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-- from my understanding is a npm run feature where it allows you to pass arguments to the underlying command. npm will basically concatenate what's on the right of -- with the script / string you define. The way it was before where npm run lint would wrap two commands, and with npm run _lint it would specify the ., so there was no way to use these pre-made scripts and "overload" your own arguments on top of the predefined ones.

In this case, I designed the npm run eslint to not include the . like it did before, so that a user that knows these conventions could run npm run eslint -- myfile.js or npm run eslint -- --fix ..

About the question about the . not being needed for tsc, it's just that somehow npm run type script is tsc --noEmit, it doesn't require a file argument like eslint does.

Copy link
Member

@geido geido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@mistercrunch mistercrunch merged commit 0f59079 into apache:master Jan 24, 2024
35 checks passed
@mistercrunch mistercrunch deleted the improve_npm_commands_lint branch January 24, 2024 16:51
eschutho pushed a commit to preset-io/superset that referenced this pull request Jan 31, 2024
sfirke pushed a commit to sfirke/superset that referenced this pull request Mar 22, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 4.0.0 labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 4.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants