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
Conversation
Thanks for working on this! Looks good so far! |
…olt-js to node-slack-sdk. Updated type/code generator 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.
…from logger package.
4b71893
to
84f0731
Compare
…uns as part of testing. Should save some CI time.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
packages/oauth/src/index.ts
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 {}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response_metadata: Record<string, never>; // TODO | |
response_metadata: Record<string, never>; // TODO revisit this type to see whether there are better alternatives |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this 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 👍
packages/oauth/src/index.spec.js
Outdated
@@ -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' }; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
packages/oauth/src/index.ts
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
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 theweb-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 (replacingtslint:disable
witheslint-disable
)lint-configs/
directorySummary of changes so far:
scripts/code_generator.rb
) to drop in aneslint-disable
directive into generated code instead of atslint:disable
one.lint-configs
directory.packages/web-api
andlint-configs
directories.Questions
package.json
differentiate between linting vs. testing each sub-project? i.e.lerna run lint
andlerna run test
being separate? Alternatively, can include linting in each sub-project'stest
npm run script, and drop the execution oflerna 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
tslint:disable
directives.npmignore
files to make sure published packages don't include any of the new eslint config filesnpm i
from the root directory to ensure you have eslint-plugin-jsdoc installedRequirements (place an
x
in each[ ]
)