-
Notifications
You must be signed in to change notification settings - Fork 30.6k
chore(node): apply lint #29151
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(node): apply lint #29151
Conversation
|
@SimonSchick Thank you for submitting this PR! 🔔 @joeskeen @aznnomness @cspotcode @chrootsu @jeffmay @basarat @barbatus @fullflavedave @orefalo @dagatsoin @birkskyum @ardatan @stefanholzapfel @andrei-markeev @lmachens @parambirs @tellnes @WilcoBakker @octo-sniffle @smac89 @Flarna @mwiktorczyk @wwwy3y3 @DeividasBakanas @kjin @alvis @eps1lon @Hannes-Magnusson-CK @jkomyno @ajafff @hoo29 @n-e @BrunoScheufler @mohsen1 @KSXGitHub @a-tarasyuk @islishude @r3nya @ZaneHannanAU @ThomasdenH @eyqs @matthieusieben @Morfent @nonAlgebraic @wokim @heycalmdown @stevehipwell @nickiannone @ashleybrener - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
Note: Changes caused some other packages to fail, is there any way to test this locally @basarat ? |
|
Another update: |
|
@SimonSchick The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
@SimonSchick The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
| maxKeys?: number; | ||
| decodeURIComponent?: Function; | ||
| } | ||
|
|
||
| interface ParsedUrlQuery { [key: string]: string | string[] | undefined; } | ||
| interface ParsedUrlQuery { [key: string]: string | string[]; } |
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 reason why | undefined was used here is that this allows you to augment ParsedUrlQuery like this in your application to easier access properties:
my_key?: string,
my_arr_key?: string[]
}
if | undefined is not there it's only possible to specify mandatory properties.
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'm not following, can you provide an example maybe?
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.
let result: querystring.ParsedUrlQuery;
const a: {
a?: string;
} = result;
works just fine in this case (pulled from test).
If you are talking about augmenting the interface through declaration merging however:
I think it's a really really bad practise to do that as you can have various definitions of query string parameters for all sorts of purposes, you should cast to your desired type instead.
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.
See the http.IncomingHttpHeaders which holds an index signature on the one hand and named optional properties on the other hand to narrow types for known/specified headers. This works only if | undefined is added in the index signature.
Users could do the same by augmenting ParsedUrlQuery but I agree that this is different and not really an intended usecase.
types/node/index.d.ts
Outdated
| function request(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; | ||
| function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest; | ||
| function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; | ||
| const globalAgent: Agent; |
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.
globalAgent is not const.
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.
Seems that way, however changing it on the fly could break references.
I will change it to let.
|
|
||
| // Same as module.exports | ||
| declare var exports: any; | ||
| declare var SlowBuffer: { | ||
| declare const exports: any; |
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 this really const?
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.
Usually exports is passed in by the nodejs module wrapper as an argument.
It is debatable if this is const but assigning it effectively breaks exports as you are changing the reference, you should always set module.exports
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, right. adding properties to exports is the usecase, not assigning to it.
types/node/index.d.ts
Outdated
| function request(url: string | URL, options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest; | ||
| function get(options: RequestOptions | string | URL, callback?: (res: http.IncomingMessage) => void): http.ClientRequest; | ||
| function get(url: string | URL, options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest; | ||
| const globalAgent: Agent; |
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 think this is not const. It may be a valid usecase to modify the global agent in an application.
|
Quite a big changeset so maybe I haven't overlooked something... |
|
A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
|
@Flarna I am aware it's generated but the link to the generator is dead so I dunno where it is 😛 |
islishude
left a comment
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.
Remove so much export,I don't think that's the right thing to do. there may be compatibility problems.
|
@SimonSchick One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you! |
|
@islishude The linter made it clear these export keywords were redundant, (except for http2). |
|
@SimonSchick Isn't the generator in the subfolder types/node/scripts/generate-inspector? |
|
@Flarna my bad, I had |
|
Update: |
|
Hey @basarat I think this is ready. |
| export function parse<T extends {}>(str: string, sep?: string, eq?: string, options?: ParseOptions): T; | ||
| export function escape(str: string): string; | ||
| export function unescape(str: string): string; | ||
| function stringify(obj?: {}, sep?: string, eq?: string, options?: StringifyOptions): string; |
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 think the first argument is mandatory.
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.
Forgive the ghetto windows shell:
C:\Users\Simon>node -v
v10.10.0
C:\Users\Simon>node
> querystring.stringify(undefined)
''
> querystring.stringify()
''
>
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.
ok, behavior of node and doc differs here.
|
@Flarna I think you're still reviewing - please let me know if/when you're satisfied. |
ThomasdenH
left a comment
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 only comment I have is the usage of <any> casting instead of using as any. This is the recommended syntax.
types/grunt/grunt-tests.ts
Outdated
| // exports should work same as module.exports | ||
| exports = (grunt: IGrunt) => { | ||
| // assigning exports is an error in node, hence the cast | ||
| (<any>global).exports = (grunt: IGrunt) => { |
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.
Isn't the as syntax recommended now?
types/node/node-tests.ts
Outdated
| let x: NodeModule; | ||
| let y: NodeModule; | ||
| const x: NodeModule = <any> {}; | ||
| const y: NodeModule = <any> {}; |
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.
Same here. as is recommended instead.
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 suppose, not a big change, but this should really be added to the lint config if it's so important @basarat
types/node/node-tests.ts
Outdated
| { | ||
| let http2Stream: http2.Http2Stream; | ||
| let duplex: stream.Duplex = http2Stream; | ||
| const http2Stream: http2.Http2Stream = <any> {}; |
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.
Casting without as.
types/node/node-tests.ts
Outdated
|
|
||
| // ClientHttp2Stream | ||
| let clientHttp2Stream: http2.ClientHttp2Stream; | ||
| const clientHttp2Stream: http2.ClientHttp2Stream = <any> {}; |
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.
Casting without as.
| let serverHttp2Stream: http2.ServerHttp2Stream; | ||
| let headers: http2.OutgoingHttpHeaders; | ||
| const serverHttp2Stream: http2.ServerHttp2Stream = <any> {}; | ||
| const headers: http2.OutgoingHttpHeaders = {}; |
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.
Casting without as.
types/node/node-tests.ts
Outdated
| const onConnectHandler = (session: http2.Http2Session, socket: net.Socket) => {}; | ||
|
|
||
| let serverHttp2Session: http2.ServerHttp2Session; | ||
| const serverHttp2Session: http2.ServerHttp2Session = <any> {}; |
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.
Casting without as.
types/oauth/oauth-tests.ts
Outdated
| /** Github sends auth code so that access_token can be obtained */ | ||
| /** To obtain and parse code='...' from code?code='...' */ | ||
| const qsObj = qs.parse<{[key: string]: string}>(p[1].split('?')[1]); | ||
| const qsObj = <{ code: string }> qs.parse(p[1].split('?')[1]); |
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.
Casting without as.
|
Not sure if you saw, but there are still these instances of casting with
|
|
@ThomasdenH I appreciate the thoroughness but I don't think we should be this nit-picky about this. |
|
You're probably right. Still, since the PR is about style anyway I think it's a good idea. Anyway, looks good to me now! |
I changing an existing definition:
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }.This applies most lint rules, except ones that would introduce too many breaking changes.
The main changes here are:
exportkeywords (http2 is a special case)constinstead ofvar, this might be debatable because some may re-write globals, please advise.This (for now) includes #29147