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

[#174416949] ESLint config #1

Merged
merged 20 commits into from
Jan 7, 2021
Merged

[#174416949] ESLint config #1

merged 20 commits into from
Jan 7, 2021

Conversation

BurnedMarshal
Copy link
Contributor

@BurnedMarshal BurnedMarshal commented Dec 17, 2020

Porting TSLint rules configuration from io-tslint-rules to ESLint and merged with io-pay ESLint configuration .

The following TSLint rules are not supported for eslint at the moment:

bool-param-default
max-union-size
no-accessor-field-mismatch
no-array-delete // Mitigated by no-delete
no-case-with-or
no-dead-store
no-duplicate-in-composite
no-empty-array
no-extra-semicolon // Mitigated by prettier
no-empty-destructuring // Mititgated by no-empty-pattern
no-gratuitous-expressions
no-hardcoded-credentials
no-ignored-initial-value // Mitigated by no-param-reassign, no-let
no-in-misuse
no-inferred-empty-object-type
no-invalid-await // Mititgated by await-thenable
no-invariant-return
no-misleading-array-reverse // Mitigated by immutable-data
no-misspelled-operator // Mitigated by prettier
no-nested-switch
no-nested-template-literals
no-statements-same-line // Mitigated by prettier
no-try-promise
no-tslint-disable-all
no-unconditional-jump
no-undefined-argument
no-unenclosed-multiline-block // Mitigated by prettier
no-unthrown-error
no-unused-array // Mitigated by no-unused-vars
no-useless-increment
no-useless-intersection
prefer-promise-shorthand
promise-must-complete
use-primitive-type

@BurnedMarshal BurnedMarshal requested review from francescopersico and gunzip and removed request for gunzip and francescopersico December 17, 2020 16:39
@BurnedMarshal BurnedMarshal marked this pull request as ready for review December 21, 2020 12:22
Copy link

@AleDore AleDore left a comment

Choose a reason for hiding this comment

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

LGTM apart from minor tuning

"functional/immutable-data": "error",
"sonarjs/no-small-switch": "off",
"sonarjs/no-duplicate-string": "error",
"sonarjs/cognitive-complexity": ["error", 19],
Copy link

Choose a reason for hiding this comment

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

We must check on TSLint what is the current cap on cognitive complexity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default value is 15, we can use it and eventually tuning the value at the project level.

Copy link

@gunzip gunzip left a comment

Choose a reason for hiding this comment

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

can you add a readme.md with the user manual ? (how to integrate in new projects and how to migrate from tslint in existing ones)

package.json Outdated
@@ -0,0 +1,34 @@
{
"name": "io-eslint-rules",
Copy link

Choose a reason for hiding this comment

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

why the package and repo names diverge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name of the package must be @pagopa/eslint-config to work properly. See this ESLint documentation reference. If we want we can rename the repo to eslint-config. Fixed in 7dd1a75

tsconfig.json Outdated

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
Copy link

Choose a reason for hiding this comment

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

why not es6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tsconfig.json Outdated
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"lib": ["es2015"], /* Specify library files to be included in the compilation. */
Copy link

Choose a reason for hiding this comment

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

es6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tsconfig.json Outdated
@@ -0,0 +1,70 @@
{
Copy link

Choose a reason for hiding this comment

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

why do we need a tsconfig.json here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was added for local testing inside this project. We can safely remove it. Fixed in 1a44979

@BurnedMarshal
Copy link
Contributor Author

can you add a readme.md with the user manual ? (how to integrate in new projects and how to migrate from tslint in existing ones)

@gunzip A small README content was added in 32366af and 96e3e9e

BurnedMarshal and others added 2 commits December 21, 2020 15:58
Co-authored-by: Emanuele De Cupis <[email protected]>
Co-authored-by: Emanuele De Cupis <[email protected]>
Copy link
Contributor

@balanza balanza left a comment

Choose a reason for hiding this comment

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

LGTM apart minor comments

"object-shorthand": "error",
"no-var": "error",
"no-param-reassign": "error",
"no-underscore-dangle": "error",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if it would break our convention of prefixing unused params with underscore. In case, we can add

Suggested change
"no-underscore-dangle": "error",
"no-underscore-dangle": ["error", { "allowFunctionParams": true }],

See https://eslint.org/docs/rules/no-underscore-dangle#options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is, "allowFunctionParams": true (default) allows dangling underscores in function parameter names

Copy link
Contributor

Choose a reason for hiding this comment

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

So we want it or not? I think we want to be able to write

const fn = (_p) => {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, maybe my comment wasn't clear. We can write const fn = (_p) => {}, the option allowFunctionParams has true as default value.

complexity: "error",
"arrow-body-style": "error",
"import/no-internal-modules": "off",
"import/order": "error",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine in having this, but I question if it's really useful

@balanza
Copy link
Contributor

balanza commented Dec 21, 2020

Great job guys! I'm loving this <3

@@ -1,5 +1,5 @@
{
"name": "eslint-config",
"name": "@pagopa/eslint-config",
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

Comment on lines +6 to +12
steps:
- task: Npm@1
inputs:
command: 'publish'
workingDir: '.'
publishEndpoint: 'NPM Registry'
verbose: true
Copy link
Contributor

Choose a reason for hiding this comment

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

this won't work as per this issue microsoft/azure-pipelines-tasks#14165
However we implemented a workaround here pagopa/io-functions-commons#131

I suggest you to do it in another PR in which you can refactor the whole pipeline

@balanza balanza merged commit 02ef13a into master Jan 7, 2021
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.

4 participants