Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

[Cleanup] Enable noUnusedLocals/Parameters and remove all refs #877

Merged
merged 1 commit into from
Dec 9, 2017

Conversation

damassi
Copy link
Member

@damassi damassi commented Dec 7, 2017

One thing I noticed when I first started working in Emission was all of the unused variables and imports. There's a TSLint rule available, but since the check occurs in TypeScript it never gets fired. This PR enables noUnusedLocals and noUnusedParameters in tsconfig.json and sweeps through the code.

While making edits I also found handful of unguarded error code for which I entered console.errors and FIXME: Handle error notes.

Skip New Tests

There are a couple questions which I've noted inline.

"typescript.format.enable": false
"typescript.format.enable": false,
"[json]": {
"editor.formatOnSave": false
Copy link
Member Author

Choose a reason for hiding this comment

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

For whatever reason, rules like "require trailing comma" would auto-fix in .json files making it impossible to produce correct JSON.


// FIXME: This isnt being used
Copy link
Member Author

Choose a reason for hiding this comment

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

In some of the more ambiguous "WIP?" areas I've commented out and added a note

Copy link
Contributor

Choose a reason for hiding this comment

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

This can go, the root component decorator is called screenTrack.

} | null
}
}
// FIXME: This is being unused in code
Copy link
Member Author

@damassi damassi Dec 7, 2017

Choose a reason for hiding this comment

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

There were many instances of there being a interface Props { ... } at the top of the file that had the exact same props as interface RelayProps { ... } at the bottom of the file, though at the top it typically lacked | null. Why is this? In most instances they're nearly identical so why is one not being used?

Copy link
Contributor

Choose a reason for hiding this comment

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

The RelayProps were being auto generated. I guess someone didn’t realize these existed and manually added them to Props rather than extending.

Copy link
Contributor

Choose a reason for hiding this comment

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

The RelayProps that add null are more correct, though.

@damassi damassi force-pushed the chris-add-noUnusedLocals-and-fix branch from 2e65561 to 780b468 Compare December 7, 2017 04:27
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 7, 2017
"plugins": [{ "name": "typescript-styled-plugin" }],
"baseUrl": "src"
"target": "es6",
"types": ["jest", "react", "react-native"]
Copy link
Member Author

Choose a reason for hiding this comment

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

Just alpha + addition of noUnusedLocals and noUnusedParameters

@@ -5,10 +5,11 @@
"interface-name": [true, "never-prefix"],
"max-classes-per-file": [false],
"member-access": [false, "check-accessor", "check-constructor"],
"no-console": [true, ["error", ["warn", "error"]]],
"no-unused-variable": [true, { "ignore-pattern": "^_" }],
Copy link
Member Author

@damassi damassi Dec 7, 2017

Choose a reason for hiding this comment

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

Alpha + added the ability to ignore variables via _, similar to TypeScript compiler. This combined with new TypeScript setting worked well as TSLint seemed to not check anything but parameters once the TypeScript settings were introduced.

(See palantir/tslint#1618 for related info.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

@damassi damassi force-pushed the chris-add-noUnusedLocals-and-fix branch from 780b468 to d6c64f6 Compare December 7, 2017 05:08
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 7, 2017
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 7, 2017
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 7, 2017
@damassi damassi force-pushed the chris-add-noUnusedLocals-and-fix branch from bb4210d to 0b1d05b Compare December 7, 2017 05:40
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 7, 2017
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 7, 2017
@@ -20,7 +18,7 @@ import { isCloseToBottom } from "lib/utils/isCloseToBottom"
import { ArtistRelayProps } from "./RelayConnections/ArtistForSaleArtworksGrid"
import { GeneRelayProps } from "./RelayConnections/GeneArtworksGrid"

export const PageSize = 10
import { PAGE_SIZE } from "lib/data/constants"
Copy link
Member Author

Choose a reason for hiding this comment

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

I saw PAGE_SIZE being repeated all over so added this new constants file here (unless there's a better location)

@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 7, 2017
const filename = file.split(/\//g).pop()

// FIXME: This is being unused in 103; does this uploader work?
// const filename = file.split(/\//g).pop()
Copy link
Member Author

Choose a reason for hiding this comment

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

This is weird, check out https://github.com/artsy/emission/pull/877/files#diff-1e4221a2b438a2ae235d95aff0c14c71L103 (a few lines down from here)

key: geminiKey + "/${filename}",

Is the uploader even working? Should have backticks for interpolation

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 is weird, but that's actually what it expects ( this is the web version of this code: https://github.com/artsy/gemup/blob/master/gemup.js#L44 )

Copy link
Contributor

@alloy alloy left a comment

Choose a reason for hiding this comment

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

Great stuff thus far @damassi, much appreciated! 👏

@@ -38,7 +35,7 @@ const Artist: React.SFC<ArtistProps> = track<ArtistProps>(props => {
}
})(props => <ArtistRenderer {...props} render={renderWithLoadProgress(Containers.Artist, props)} />)

const Inbox: React.SFC<{}> = track<{}>(props => {
const Inbox: React.SFC<{}> = track<{}>(_props => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just () => { ... } ?

// const Sale: React.SFC<{ saleID: string }> = ({ saleID }) => {
// const initialProps = { saleID }
// return <SaleRenderer {...initialProps} render={renderWithLoadProgress(Containers.Sale, initialProps)} />
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the sale view is a WIP that @ashfurrow works on.

Copy link
Member Author

Choose a reason for hiding this comment

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

After talking with ash confirmed this is on hold for the time being but will leave it around for now

} | null
}
}
// FIXME: This is being unused in code
Copy link
Contributor

Choose a reason for hiding this comment

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

The RelayProps were being auto generated. I guess someone didn’t realize these existed and manually added them to Props rather than extending.

} | null
}
}
// FIXME: This is being unused in code
Copy link
Contributor

Choose a reason for hiding this comment

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

The RelayProps that add null are more correct, though.

const isPadHorizontal = Dimensions.get("window").height > 700

// TODO: Reenable when used
// const isPadHorizontal = Dimensions.get("window").height > 700
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just remove for now?

// tslint:disable-next-line:no-var-requires
const chevron: ImageURISource = require("../../../images/horizontal_chevron.png")
// const chevron: ImageURISource = require("../../../images/horizontal_chevron.png")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this simply be removed?

@@ -5,10 +5,11 @@
"interface-name": [true, "never-prefix"],
"max-classes-per-file": [false],
"member-access": [false, "check-accessor", "check-constructor"],
"no-console": [true, ["error", ["warn", "error"]]],
"no-unused-variable": [true, { "ignore-pattern": "^_" }],
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 7, 2017
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 8, 2017
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 8, 2017
@damassi
Copy link
Member Author

damassi commented Dec 8, 2017

Ok addressed all feedback and re-added RelayTypes so ready to go. Was impressed by how few ?'s are used throughout interface props code!

@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 8, 2017
@damassi damassi force-pushed the chris-add-noUnusedLocals-and-fix branch from 3a60e0a to 5e0b8db Compare December 8, 2017 05:41
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 8, 2017
@@ -5,11 +5,11 @@ import { createFragmentContainer, graphql } from "react-relay"
import SerifText from "../../Text/Serif"
import Article from "./Article"

interface Props extends ViewProperties {
interface Props extends RelayProps, ViewProperties {
articles: any[]
Copy link
Contributor

Choose a reason for hiding this comment

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

This prop is overriding the actual one from RelayProps.

not_for_sale_artworks: any[]
for_sale_artworks: any[]
}
interface Props extends RelayProps, ViewProperties {
relay: any
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 believe this prop is actually used in this module, but if it is then maybe pull in the appropriate typing from react-relay?

@@ -5,7 +5,7 @@ import { LayoutChangeEvent, StyleSheet, View, ViewProperties, ViewStyle } from "

import Show from "./Show"

interface Props extends ViewProperties {
interface Props extends RelayProps, ViewProperties {
showSize: "medium" | "large"
shows: any[]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is overriding the actual typing from RelayProps.

// }
interface RelayProps {
artist: {
__id: string | null
Copy link
Contributor

Choose a reason for hiding this comment

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

This prop is not being requested by the fragment, so shouldn’t be here.

@damassi damassi force-pushed the chris-add-noUnusedLocals-and-fix branch from 5e0b8db to d8169b5 Compare December 8, 2017 17:44
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 8, 2017
@damassi damassi force-pushed the chris-add-noUnusedLocals-and-fix branch 2 times, most recently from f4522b3 to 0a2dbef Compare December 8, 2017 22:36
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 8, 2017
@damassi damassi force-pushed the chris-add-noUnusedLocals-and-fix branch from 0a2dbef to 5430b7d Compare December 8, 2017 22:40
}

render() {
const forSaleCount = this.props.artist.counts.for_sale_artworks
const otherCount = this.props.artist.counts.artworks - forSaleCount
const otherCount = (this.props.artist.counts.artworks as number) - (forSaleCount as number)
Copy link
Member Author

Choose a reason for hiding this comment

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

@alloy - after fixing my typechecker and eliminating some of those top-of-the file Props overrides things got a little stricter and this one was interesting to try to understand...

If you look here and here (this components child) and notice the types, they both say

boolean | number | string | null

Since they're both cast to any of four types the compiler can't make basic inferences, right? And so casting it explicitly above set it through the whole chain?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, you’re code is correct. Because this value could be of a non number type (according to the typing at least), TS will complain that you can’t just subtract. Casting as a subtype, that is, one of the types in this union allows you to do so.

I don’t recall exactly why these typings are a union like that. Is the field a custom GraphQL scalar? If so, iirc those are indeed not very specific :(

@damassi damassi force-pushed the chris-add-noUnusedLocals-and-fix branch from 5430b7d to d28dbab Compare December 8, 2017 22:54
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 8, 2017
@damassi damassi force-pushed the chris-add-noUnusedLocals-and-fix branch from d28dbab to 6dfaa78 Compare December 8, 2017 22:56
@alloy
Copy link
Contributor

alloy commented Dec 9, 2017

All looks good to me. Great work! Merge when you think it’s good to go 👍

@damassi damassi merged commit 58d84f1 into master Dec 9, 2017
@damassi damassi deleted the chris-add-noUnusedLocals-and-fix branch December 9, 2017 18:25
@artsy-peril artsy-peril bot deleted a comment from ArtsyOpenSource Dec 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants