Skip to content

chore(utils): handle a few SNC violations related to path extensions and diagnostics#4903

Merged
tanner-reits merged 3 commits intomainfrom
treits/chore/util-sncs
Oct 9, 2023
Merged

chore(utils): handle a few SNC violations related to path extensions and diagnostics#4903
tanner-reits merged 3 commits intomainfrom
treits/chore/util-sncs

Conversation

@tanner-reits
Copy link
Contributor

@tanner-reits tanner-reits commented Oct 5, 2023

What is the current behavior?

SNC violations are bad

GitHub Issue Number: N/A

What is the new behavior?

There are less of them 🎉

Does this introduce a breaking change?

  • Yes
  • No

Testing

Tests continue to pass

Other information

@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2023

--strictNullChecks error report

Typechecking with --strictNullChecks resulted in 1413 errors on this branch.

That's 5 fewer than on main! 🎉🎉🎉

reports and statistics

Our most error-prone files
Path Error Count
src/dev-server/index.ts 37
src/mock-doc/serialize-node.ts 36
src/dev-server/server-process.ts 32
src/compiler/build/build-stats.ts 27
src/compiler/output-targets/dist-lazy/generate-lazy-module.ts 25
src/compiler/style/test/optimize-css.spec.ts 23
src/testing/puppeteer/puppeteer-element.ts 23
src/compiler/prerender/prerender-main.ts 22
src/runtime/vdom/vdom-render.ts 20
src/runtime/client-hydrate.ts 19
src/screenshot/connector-base.ts 19
src/compiler/config/test/validate-paths.spec.ts 16
src/dev-server/request-handler.ts 15
src/compiler/prerender/prerender-optimize.ts 14
src/compiler/sys/stencil-sys.ts 14
src/compiler/transpile/transpile-module.ts 14
src/runtime/vdom/vdom-annotations.ts 14
src/sys/node/node-sys.ts 14
src/compiler/build/build-finish.ts 13
src/compiler/prerender/prerender-queue.ts 13
Our most common errors
Typescript Error Code Count
TS2345 429
TS2322 406
TS18048 310
TS18047 100
TS2722 38
TS2532 34
TS2531 23
TS2454 14
TS2352 13
TS2769 10
TS2790 10
TS2538 8
TS2344 5
TS2416 4
TS2493 3
TS18046 2
TS2684 1
TS2488 1
TS2464 1
TS2430 1

Unused exports report

There are 12 unused exports on this PR. That's the same number of errors on main, so at least we're not creating new ones!

Unused exports
File Line Identifier
src/runtime/bootstrap-lazy.ts 21 setNonce
src/screenshot/screenshot-fs.ts 18 readScreenshotData
src/testing/testing-utils.ts 198 withSilentWarn
src/utils/index.ts 140 CUSTOM
src/compiler/app-core/app-data.ts 25 BUILD
src/compiler/app-core/app-data.ts 114 Env
src/compiler/app-core/app-data.ts 116 NAMESPACE
src/compiler/fs-watch/fs-watch-rebuild.ts 123 updateCacheFromRebuild
src/compiler/types/validate-primary-package-output-target.ts 62 satisfies
src/compiler/types/validate-primary-package-output-target.ts 62 Record
src/testing/puppeteer/puppeteer-declarations.ts 485 WaitForEventOptions
src/compiler/sys/fetch/write-fetch-success.ts 7 writeFetchSuccessSync

const dups = new Set<string>();

for (let i = 0; i < diagnostics.length; i++) {
const d = normalizeDiagnostic(compilerCtx, diagnostics[i]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed this since we import our declaration types as d which just made it confusing

lineNumber: beforeLineIndex + 1,
text: srcLines[beforeLineIndex],
errorCharStart: -1,
if (diagnostic.absFilePath) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like a big diff, just moved all the existing code under this check

const filePath = normalizePath(pathParts[0]);
const ext = filePath.split('.').pop().toLowerCase();
const filePathParts = filePath.split('.');
const ext = filePathParts.length > 1 ? filePathParts.pop()!.toLowerCase() : null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Felt wrong to return the path as the "extension" if it did not actually have an extension, so allowed this to have a null value. That's why the associated test had to change here too

Copy link
Contributor

Choose a reason for hiding this comment

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

are we pretty certain nothing depends on that old behavior?

Copy link
Member

@rwaskiewicz rwaskiewicz Oct 6, 2023

Choose a reason for hiding this comment

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

The only thing I could think of is dot files (e.g. .eslintrc) - but I'm not entirely sure/will leave that to @tanner-reits 😉

Copy link
Contributor Author

@tanner-reits tanner-reits Oct 8, 2023

Choose a reason for hiding this comment

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

I don't think this change will mess with anything. This function is only used in a single Rollup plugin where we only use the extension for two cases:

  1. If the extension is in a pre-defined list of extensions. Which, as of now, only includes txt, frag, and vert. Truthfully, I have no idea what a .frag or .vert file are 🤷‍♂️
  2. Another check for if it's an svg

In all these cases. Since there is a finite list of traditional extensions, we can safely change the function to return null if there isn't an extension and know we will just pass over these checks. As for dot-files (even though they don't really matter here), we'd still return the filename as the "extension" as before.

@tanner-reits tanner-reits marked this pull request as ready for review October 5, 2023 21:00
@tanner-reits tanner-reits requested a review from a team as a code owner October 5, 2023 21:00
const getExt = (filePath: string): string | null => {
const fileParts = filePath.split('.');

return fileParts.length > 1 ? fileParts.pop()!.toLowerCase() : null;
Copy link
Member

Choose a reason for hiding this comment

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

No action required - I think we can avoid having to use the bang operator if we break this down into 2 statements:

Suggested change
return fileParts.length > 1 ? fileParts.pop()!.toLowerCase() : null;
const extension = fileParts.pop();
return extension ? extension.toLowerCase() : null;

That said, I doubt the typings for Array.pop will change such that the bang operator we have here today will be unnecessary, so no action required

Copy link
Contributor

@alicewriteswrongs alicewriteswrongs left a comment

Choose a reason for hiding this comment

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

just one Q

const filePath = normalizePath(pathParts[0]);
const ext = filePath.split('.').pop().toLowerCase();
const filePathParts = filePath.split('.');
const ext = filePathParts.length > 1 ? filePathParts.pop()!.toLowerCase() : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

are we pretty certain nothing depends on that old behavior?

@tanner-reits tanner-reits added this pull request to the merge queue Oct 9, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 9, 2023
@tanner-reits tanner-reits added this pull request to the merge queue Oct 9, 2023
Merged via the queue into main with commit be61339 Oct 9, 2023
@tanner-reits tanner-reits deleted the treits/chore/util-sncs branch October 9, 2023 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants