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

Replace TSLint with ESLint #1325

Merged
merged 19 commits into from Sep 13, 2021
Merged

Replace TSLint with ESLint #1325

merged 19 commits into from Sep 13, 2021

Conversation

filmaj
Copy link
Contributor

@filmaj filmaj commented Sep 1, 2021

Work In Progress!

Summary

This is a first go at introducing the ESLint configs we converged on in the bolt-js project to this project. Did you all think you would be free of thousands of lines of changes moving commas around and introducing newline characters? Well think again! 😈

The initial pull request includes changes that will be core and applicable to all published packages making up this repository as well as changes to packages/web-api/src code to have the web-api package adhere to the new lint configuration. As a result, the most important changes to review include:

  • scripts/code_generator.rb: changes to the type generator script (replacing tslint:disable with eslint-disable)
  • Copies ESLint config files from bolt-js into a new lint-configs/ directory
  • What do people think of the approach of symlinking the eslint config files into each published package's directory? Any alternatives or better approaches that we should consider?
    • Related: because the eslint config files defining the rules pull in certain dependencies, this requires putting some of the eslint dependencies (like eslint itself and the jsdoc rules) into the top-level package.

Summary of changes so far:

  • Updated type/code generator (scripts/code_generator.rb) to drop in an eslint-disable directive into generated code instead of a tslint:disable one.
  • Factored out eslint-related configs into a top-level lint-configs directory.
  • Set up symlinks to eslint configuration files between packages/web-api and lint-configs directories.

Questions

  • Symlink approach good enough?
  • Should the top-level package.json differentiate between linting vs. testing each sub-project? i.e. lerna run lint and lerna run test being separate? Alternatively, can include linting in each sub-project's test npm run script, and drop the execution of lerna run lint. IMO the latter makes sense as passing the linter should be considered necessary - and thus linting is implicitly part of the test suite.

TODO

  • Do an audit / search for tslint:disable directives
  • Review .npmignore files to make sure published packages don't include any of the new eslint config files
  • Instructions need to include running npm i from the root directory to ensure you have eslint-plugin-jsdoc installed

Requirements (place an x in each [ ])

@filmaj filmaj added the tests M-T: Testing work only label Sep 1, 2021
@filmaj filmaj self-assigned this Sep 1, 2021
@filmaj filmaj requested a review from mwbrooks September 1, 2021 18:53
@filmaj filmaj marked this pull request as ready for review September 2, 2021 12:34
@seratch
Copy link
Member

seratch commented Sep 3, 2021

Thanks for working on this! Looks good so far!

Copy link
Member

@srajiang srajiang left a comment

Choose a reason for hiding this comment

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

Looking good! Left a couple of questions/ comments! Also, are you planning on committing up a package-lock.json with these changes?

import { Logger, LogLevel, getLogger } from './logger';
import { MemoryInstallationStore } from './stores';

// default implementation of StateStore
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, what's the reasoning behind moving this up? Was this related to one of the eslint rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the 'no use before defined' rule. While functions are hoisted to the top by the runtime, classes, and I guess types as well, are not.

parsedUrl = parseUrl(req.url, true);
code = parsedUrl.query.code as string;
state = parsedUrl.query.state as string;
if (state === undefined || state === '' || code === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

Wondering whether this was written this way to be a bit more explicit for people unfamiliar with the JS type coercion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rewrote this part as use of parseUrl is deprecated and that triggered an eslint rule! So I did it the 'approved' newer-node-version way of creating a new URL.

@@ -817,7 +823,7 @@ export interface OAuthV2TokenRefreshResponse extends WebAPICallResult {
team: { id: string, name: string };
enterprise: { name: string, id: string } | null;
is_enterprise_install: boolean;
response_metadata: {}; // TODO
response_metadata: Record<string, never>; // TODO
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to keep this comment in this line now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! I think so but am not sure - Record seems like a barely-more-acceptable type than {}?

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
response_metadata: Record<string, never>; // TODO
response_metadata: Record<string, never>; // TODO revisit this type to see whether there are better alternatives

Copy link
Member

Choose a reason for hiding this comment

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

The property can exist but actually the value is not used. The internal type def is an alias of https://github.com/slackapi/node-slack-sdk/blob/main/packages/web-api/src/response/OauthV2AccessResponse.ts See also: https://github.com/slackapi/node-slack-sdk/blob/%40slack/oauth%402.2.0/packages/oauth/src/index.ts#L209-L214

You can safely remove the property. Let's remove it! If you hesitate to have potentially breaking changes in this PR, update the TODO comment to inclue my comment 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.

Sounds good, I have removed it in the most recent commit!

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

No other comments! Thanks for the massive efforts here 👍

@@ -398,7 +398,7 @@ describe('OAuth', async () => {
});

it('should call the failure callback due to missing state query parameter on the URL', async () => {
const req = { url: 'someUrl' };
const req = { url: 'http://someUrl.com' };
Copy link
Member

Choose a reason for hiding this comment

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

It seems that this domain is used. Just in case, how about using example.com?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good idea. In fact, this change is related to another change (see my related review comment here). Because of the removal of the use of parseUrl (which is deprecated) and replacing it with new URL(), if the protocol and/or TLD is not provided in the URL string, it will cause an error. I wonder if this has farther-reaching consequences and as a result need to add more tests for this? For example, what if someone has custom domain mappings in their e.g. hosts file, to map e.g. someUrl to 127.0.0.1. In the current implementation, perhaps it is perfectly OK to use a technically malformed URL (no protocol and/or TLD), whereas due to this change, that would not be acceptable.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for sharing the context. My comment was not clear enough but I wanted to suggest http://example.com or https://example.com instead. If you click the URL in your editor, you will be navigated to the URL. Some people may unintentionally access the URLs.

Although I don't have any thoughts on the domain itself, I think that we can always consider using the safest domains / URLs in test data. I'm not stick with example.com at all but it's commonly used. For this reason, it should be good enough.

@@ -817,7 +823,7 @@ export interface OAuthV2TokenRefreshResponse extends WebAPICallResult {
team: { id: string, name: string };
enterprise: { name: string, id: string } | null;
is_enterprise_install: boolean;
response_metadata: {}; // TODO
response_metadata: Record<string, never>; // TODO
Copy link
Member

Choose a reason for hiding this comment

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

The property can exist but actually the value is not used. The internal type def is an alias of https://github.com/slackapi/node-slack-sdk/blob/main/packages/web-api/src/response/OauthV2AccessResponse.ts See also: https://github.com/slackapi/node-slack-sdk/blob/%40slack/oauth%402.2.0/packages/oauth/src/index.ts#L209-L214

You can safely remove the property. Let's remove it! If you hesitate to have potentially breaking changes in this PR, update the TODO comment to inclue my comment here.

@filmaj filmaj merged commit 542e5f9 into main Sep 13, 2021
@filmaj filmaj deleted the tslint-to-eslint branch September 13, 2021 19:16
@hello-ashleyintech hello-ashleyintech added this to the rtm-api@6.1.0 milestone Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests M-T: Testing work only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants