Skip to content

Comments

Add eslint-plugin-fluid package in common/build#19628

Merged
jikim-msft merged 33 commits intomicrosoft:mainfrom
jikim-msft:common/revert-custom-linter
Feb 17, 2024
Merged

Add eslint-plugin-fluid package in common/build#19628
jikim-msft merged 33 commits intomicrosoft:mainfrom
jikim-msft:common/revert-custom-linter

Conversation

@jikim-msft
Copy link
Contributor

Description

Follow up to:

Instead of creating a nested package inside the eslint-config-fluid package, this PR creates a new package to enforce custom linter rules.

@github-actions github-actions bot added area: build Build related issues base: main PRs targeted against main branch labels Feb 14, 2024
@@ -3,4 +3,4 @@
* Licensed under the MIT License.
*/

import { exceptionInternalFunction, alphaFunction2 } from "./exceptionFile.ts";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this is automatically chaning from ts to js just by moving the directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

In general imports shouldn't have ts extensions. js/cjs/mjs are ok. I imagine you probably told VSCode to auto-update imports when the file moved, and if so it did the right thing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

import { exceptionInternalFunction, alphaFunction2 } from "./exceptionFile.ts";

I think using .ts extension is acceptable as this was the case from the eslint-config-fluid package?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not really. It doesn't fail because we're not actually running those files, just linting them, but Typescript is complaining about the import even now in my local:

image

Best to just use .js even if these files are never really executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Left comment below about changing it to .ts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just importing with a .js extension causes the test to fail because there's no such .js file. Note this project doesn't do a Typescript build. The actual tests are written in .js files (src/test/enforce.../*.js), and all these .ts files inside src/test/mockFiles/ are just collateral for testing the custom linting rules, and they're never compiled. It feels right to me that the rules are tested "on top of" .ts files since that's what they would normally operate on in the wild.

For the purpose of the test, we just need that one of the .ts files is importing from another one that exports things with different API-levels, and I guess writing both in TS was the more natural thing to do. If exceptionFile was a .(c/m)js file directly and we imported from it with that extension, things probably would be fine too? We'd just need to remove the typing from it. Not sure I prefer that so much over the current state of things, maybe expanding on the comment in line 6 about why we do it.

I imagine a setup exists where we compile the collateral files during the build, so then when the tests for the custom lint rules run they have both the source and the built versions, but I'm not sure what exactly we gain from such a setup.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a test tsconfig.json - not part of the normal build, but it will be.
Of course there isn't a .js file, but .js is the way import specs should be written ... without allowImportingTsExtensions. Typescript and related evaluators should understand that a .js path may resolve to .ts or .d.ts in a Typescript context. There is no requirement that the .js file exists during Typescript linting. (Our build used to require tsc run before eslint, but that was wrong - I think I removed that requirement. If not, I will get it removed ;) )
Note that we do not use allowImportingTsExtensions in our normal tsconfig settings. The settings here should be similar to the minimal requirements for our build. (So, no allowImportingTsExtensions.)
Technically we could lint a .js file for the tags associated with the imports by looking at the corresponding .d.ts, but I think that is uncommon use case and we can ignore it.
I am concerned that the related rules are not really doing their job in the real world.

Copy link
Contributor

Choose a reason for hiding this comment

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

So the issue here might be that the "test" tsconfig.json should look more like one of our normal tsconfig.json's, and that might let the dummy TS project which gets linted in this package's tests to import from ... .js" like we do everywhere else?

Of note, I hesitate to just call it "test tsconfig.json" because that makes me think of "the tsconfig json used for the build of the tests", which at least today, this one is not; neither source nor tests have a build step in this package right now. The tsconfig.json is used for a dummy TS project "created programmatically" for the ESLint instance we create and exercise during tests.

I am concerned that the related rules are not really doing their job in the real world.

no-member-release-tags does trigger today:

image

no-restricted-tags-imports... seems not to be used today, ha.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah - it should be the "examples" tsconfig file. (I didn't go as far as to suggest relocating the file in #22005, but we definitely should when making this package use typescript.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not saying no-member-release-tags won't trigger today. I am questioning whether it is triggering everywhere we want it to. I have not looked at the rule to try to understand it.

Copy link
Contributor

@alexvy86 alexvy86 left a comment

Choose a reason for hiding this comment

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

A few comments

@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Feb 14, 2024

@fluid-example/bundle-size-tests: +187 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 511.94 KB 511.98 KB +44 Bytes
connectionState.js 680 Bytes 680 Bytes No change
containerRuntime.js 244.62 KB 244.64 KB +22 Bytes
loader.js 170.65 KB 170.67 KB +22 Bytes
map.js 46.53 KB 46.54 KB +11 Bytes
matrix.js 148.88 KB 148.9 KB +11 Bytes
odspDriver.js 97.67 KB 97.7 KB +33 Bytes
odspPrefetchSnapshot.js 42.63 KB 42.65 KB +22 Bytes
sharedString.js 168.61 KB 168.62 KB +11 Bytes
sharedTree.js 333.89 KB 333.89 KB No change
Total Size 1.87 MB 1.87 MB +187 Bytes

Baseline commit: ecb68d5

Generated by 🚫 dangerJS against 441cfee

Copy link
Contributor

@alexvy86 alexvy86 left a comment

Choose a reason for hiding this comment

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

Lgtm! One nit below.

@@ -0,0 +1,11 @@
# Generated by npm / Lerna
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these are right. This package doesn't have a package-lock.json, or printed-configs or type-tests. It might be better to remove this file and specify the .prettierignore at the repo root instead in the prettier package.json scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're referring to this .prettierignore file located in the root of the client release group right?

# Generated by npm / pnpm

eslint-plugin-fluid generates nyc and node_modules and these are already covered in the file, so I believe we wouldn't need any more addition.

Copy link
Contributor

@Josmithr Josmithr left a comment

Choose a reason for hiding this comment

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

Left a handful of suggestions, but otherwise looks good to me! Thanks for doing this!!

taskLint: false
taskTest:
- test
taskLint: false No newline at end of file
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexvy86 @Josmithr

Wanted to double check if removing taskTest is correct as the test-suites in eslint-config-fluid have been moved to the eslint-plugin-fluid package.

Copy link
Contributor

@Josmithr Josmithr Feb 16, 2024

Choose a reason for hiding this comment

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

It is correct, though I would recommend an alternative solution. I would recommend keeping this, and replacing the test script in the package with echo "TODO: add tests". That way if we add new tests later, the CI pipeline will automatically run them.

The reason I suggest this is that when we first added tests to the package a few months ago, none of us realized we needed to modify the pipeline to ensure they were running. So the tests weren't actually being run until I happened to notice that one of them was failing locally and did some digging.

Copy link
Contributor

@alexvy86 alexvy86 Feb 16, 2024

Choose a reason for hiding this comment

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

I'll just add it's actually not entirely correct 😄 , it needs to be specified as taskTest: [] otherwise the default will take over. Example where we disable them here. But I agree with Josh's suggestion to just add a test script to the package, and keep tasktest: \n - test in the pipeline.

Copy link
Contributor

@Josmithr Josmithr left a comment

Choose a reason for hiding this comment

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

Looks great! I left one more suggestion, but otherwise looks good to go! 🚀

taskLint: false
taskTest:
- test
taskLint: false No newline at end of file
Copy link
Contributor

@alexvy86 alexvy86 Feb 16, 2024

Choose a reason for hiding this comment

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

I'll just add it's actually not entirely correct 😄 , it needs to be specified as taskTest: [] otherwise the default will take over. Example where we disable them here. But I agree with Josh's suggestion to just add a test script to the package, and keep tasktest: \n - test in the pipeline.

@jikim-msft jikim-msft marked this pull request as ready for review February 17, 2024 21:29
@jikim-msft jikim-msft merged commit 394bcc8 into microsoft:main Feb 17, 2024
@jikim-msft jikim-msft deleted the common/revert-custom-linter branch March 4, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build related issues base: main PRs targeted against main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants