-
Notifications
You must be signed in to change notification settings - Fork 371
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
Add Typescript eslint #6985
Conversation
e816a55
to
ce99d9e
Compare
a742692
to
b2a74e1
Compare
@@ -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) { |
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.
Added streamData parameter instead of relying on closure
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.
@@ -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>>; |
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 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) { |
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.
this feels a bit hacky but means we get a displayName
1310353
to
109313a
Compare
.eslintrc
Outdated
"react/jsx-closing-bracket-location": ["error", "line-aligned"], | ||
"react/jsx-closing-tag-location": "error", | ||
"react/jsx-curly-spacing": ["error", "never", { "allowMultiline": true }], |
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 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
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.
Prettier recommends using eslint-config-prettier
, so we should include this
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 @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 }], |
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 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
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.
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, |
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.
eqeqeq won't actually be activated by default :(
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 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" |
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.
here you also need a plugin:@typescript-eslint/eslint-recommended
so js eslint rules are converted to ts version
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.
actually, my bad plugin:@typescript-eslint/recommended
will activate it automatically but IMO doesn't hurt to add it explicitly, your call
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'd prefer to be explicit, will add it
.eslintrc
Outdated
{ | ||
"files": ["**/*.ts", "**/*.tsx"], | ||
"extends": [ | ||
"eslint:recommended", |
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.
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
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've simplified the config so the overrides
is just changing to warn
errors still be to fixed in ts,tsx files
e47367d
to
edea374
Compare
- Warn instead of ignore new ts rules
…with prettier - Removed problematic overrides as reported by `npx eslint-config-prettier`
6714541
to
9e2661c
Compare
9e2661c
to
175eaa5
Compare
What this PR does
Fixes #3303
Special thanks to @zoran995 for their earlier PR!
yarn gulp lint --fix
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 indoc/
.