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

Add Typescript eslint #6985

Merged
merged 19 commits into from
Dec 20, 2023
Merged

Add Typescript eslint #6985

merged 19 commits into from
Dec 20, 2023

Conversation

ljowen
Copy link
Contributor

@ljowen ljowen commented Nov 27, 2023

What this PR does

Fixes #3303
Special thanks to @zoran995 for their earlier PR!

  • Enable eslint for .ts and .tsx files
  • Run yarn gulp lint --fix
  • Manually fix remaining problems. Where possible I've been conservative about changing typings or changes that could have unseen side effects.

More rules can be enable progressively

Test me

Given the blast radius exploratory testing is likely best approach along with careful review: http://ci.terria.io/typescript-eslint

Checklist

  • [] There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • [ ] I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

.eslintrc Outdated Show resolved Hide resolved
.eslintrc Outdated Show resolved Hide resolved
.eslintrc Outdated Show resolved Hide resolved
@ljowen ljowen force-pushed the typescript-eslint branch 2 times, most recently from a742692 to b2a74e1 Compare November 30, 2023 06:33
@ljowen ljowen requested a review from tephenavies December 4, 2023 00:37
@@ -88,14 +88,27 @@ export class SenapsLocationsStratum extends LoadableStratum(

static async load(senapsLocationsCatalogItem: SenapsLocationsCatalogItem) {
const locationsUrl = senapsLocationsCatalogItem._constructLocationsUrl();

function addStreamIds(f: SenapsFeature, index: number, streamData: any) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added streamData parameter instead of relying on closure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -19,6 +19,8 @@ export default function addModelStrataView<
): ModelPropertiesFromTraits<InstanceType<T>>;
export default function addModelStrataView<
T extends TraitsConstructor<ModelTraits>
/* TODO: Fix this overload type */
/* eslint-disable-next-line @typescript-eslint/ban-types */
>(model: Function, Traits: T): ModelPropertiesFromTraits<InstanceType<T>>;
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 couldn't easily find an appropriate type for model that would satisfy tsc since it seems to get treated as both a function and a class constructor

export const withViewState = <P extends WithViewState>(
Component: React.ComponentType<P>
): React.FC<Omit<P, "viewState">> =>
function withViewState(props) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this feels a bit hacky but means we get a displayName

.eslintrc Outdated
Comment on lines 37 to 39
"react/jsx-closing-bracket-location": ["error", "line-aligned"],
"react/jsx-closing-tag-location": "error",
"react/jsx-curly-spacing": ["error", "never", { "allowMultiline": true }],
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better to install eslint-config-prettier and let it handle this, I am a bit worried that those rules might cause conflicts with prettier formatting

Copy link
Member

Choose a reason for hiding this comment

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

Prettier recommends using eslint-config-prettier, so we should include this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @zoran995 I've added that and removed any rules reported by the eslint-config-prettier cli tool: https://github.com/prettier/eslint-config-prettier?tab=readme-ov-file#cli-helper-tool

"react/no-did-update-set-state": "error",
"react/no-will-update-set-state": "error",
"react/self-closing-comp": "error",
"react/jsx-no-undef": ["error", { "allowGlobals": true }],
Copy link
Collaborator

@zoran995 zoran995 Dec 18, 2023

Choose a reason for hiding this comment

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

I would also consider react/jsx-no-leaked-render and react/no-object-type-as-default-prop as they can early catch some pretty nasty stuff. In the past, there were cases when 0 was rendered due to some programmatic scroll or some weird behaviour

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These require an update to eslint-plugin-react and introduce ~100 new errors. I'll create an issue to enable and fix these rules in the interest of keeping the scope of this PR down

}
],
"dot-location": [1, "property"],
"eqeqeq": 1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

eqeqeq won't actually be activated by default :(

Copy link
Contributor Author

@ljowen ljowen Dec 19, 2023

Choose a reason for hiding this comment

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

Thanks for picking this up! I've added it back in and fixed in .ts,.tsx files

.eslintrc Outdated
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended"
Copy link
Collaborator

Choose a reason for hiding this comment

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

here you also need a plugin:@typescript-eslint/eslint-recommended so js eslint rules are converted to ts version

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually, my bad plugin:@typescript-eslint/recommended will activate it automatically but IMO doesn't hurt to add it explicitly, your call

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'd prefer to be explicit, will add it

.eslintrc Outdated
{
"files": ["**/*.ts", "**/*.tsx"],
"extends": [
"eslint:recommended",
Copy link
Collaborator

Choose a reason for hiding this comment

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

To check if this was intentional, having all those extends here will force you to specify every overriding config option in 2 places, above for .js and here for typescript files, i.e. eslint:recommended sets rule-1 to error, you disable it or change it and that here again specify eslint:recommended forcing you to specify config in two places

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've simplified the config so the overrides is just changing to warn errors still be to fixed in ts,tsx files

@ljowen ljowen merged commit e4bc336 into main Dec 20, 2023
5 checks passed
@ljowen ljowen deleted the typescript-eslint branch December 20, 2023 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Model architecture: Enable eslint for .ts files
3 participants