Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

[FEAT] Recommended config #261

Merged
merged 34 commits into from
Dec 22, 2018
Merged

[FEAT] Recommended config #261

merged 34 commits into from
Dec 22, 2018

Conversation

bradzacher
Copy link
Owner

@bradzacher bradzacher commented Dec 21, 2018

Fixes #144
Requires #259, #260.

  • added a util to make it standardised and easier to add default config for a rule
  • configured recommended based on add a recommended preset #144
    • purposely switched recommended prop to be "error" | "warning" | false
      • inside the eslint repo, it should be true. otherwise it's just a property that isn't used officially by eslint. It's truthy so eslint-docs still work.
    • changed recommended generator to accept "error"/"warning" for more configurability.
  • adjusted default config of certain rules that didn't match our recommendations.

Copy link

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

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

docment its usage? I'm not seeing the docs update, am I missing something?

@bradzacher
Copy link
Owner Author

@aladdin-add - I have updated the readme

@armano2
Copy link
Contributor

armano2 commented Dec 21, 2018

@bradzacher looks like there are errors in tests for no-type-alias

# Conflicts:
#	lib/rules/no-type-alias.js
#	lib/util.js
@bradzacher
Copy link
Owner Author

@armano2 yup - it needed the config changes from #259

# Conflicts:
#	README.md
#	lib/configs/recommended.json
#	lib/rules/no-unused-vars.js
Copy link

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@bradzacher bradzacher merged commit 2087aac into master Dec 22, 2018
@bradzacher bradzacher deleted the recommended branch December 22, 2018 20:12
@arvigeus
Copy link

It does not work for me. ESLint complains that "warning" should be "warn" instead. Bonus question: how to make it work with prettier?

@aladdin-add
Copy link

it was fixed in master, but not released yet.

@bradzacher plan to release a patch version?

@bradzacher
Copy link
Owner Author

I'm back from holidays so I'll look to cleaning things up and releasing rc.1

"typescript/explicit-function-return-type": "warning",
"typescript/explicit-member-accessibility": "error",
"indent": "off",
"typescript/indent": "error",

Choose a reason for hiding this comment

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

recommended was designed to only contain possible errors and best practices rules, the typescript/indent as a stylistic rule, I'm not sure if it could be included in the recommended.

Copy link

Choose a reason for hiding this comment

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

I agree. Although it seems like all remommended rulesets out there include stylistic rules as well, probably for the folks who don't use prettier. I think the best solution would be to leave these rules in recommended, and add plugin:typescript/prettier to shut them off. Thoughts?
I also noticed other differences compared to tslint:recommended, for example complaining about using IFoo as interface name instead of Foo. Correct me if I am wrong, but IFoo seems like the more popular convention, although on typescript docs site I don't see them used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There’s an eslint-config-prettier, which I’m going to add a typescript preset to (prettier/eslint-config-prettier#68), which will disable all stylistic rules. People could then extend ["plugin:typescript/recommended", "prettier/typescript"].

Copy link
Contributor

Choose a reason for hiding this comment

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

we should not enable stylistic rules as recommended, they are opinionated, some ppl prefer tabs over spaces xd

Copy link
Owner Author

Choose a reason for hiding this comment

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

As a general rule, we turn on rules based on what is considered best practice - which we've been deriving from the TS team (their docs and the playground).

The goal of eslint is to help developers enforce consistency on their codebase.

@arvigeus - Using IFoo is an antipattern; a naming convention derived from languages like C#/Java where interfaces are pretty much a tangible thing at runtime; so you don't want people to confuse them with classes.
In TS; interfaces are compile-time only. Also (when it comes to object typing) there is very little difference between interface Foo and type Foo, which begs the question of why you'd choose to name it interface IFoo, but name types type Foo.
This is the style the typescript docs have been using for a long while, so we recommend people follow that.

As for indent - typescript docs use 4 spaces, as does the typescript playground, hence we recommend that too. Additionally, I'm yet to see a TS codebase that doesn't enforce some form of indentation standard.
Whilst everyone is different, turning on the rule by default serves two purposes:

  1. it alerts the user that there is in fact an indentation rule, so they can reconfigure it if they want tabs / n spaces.
  2. it lets us ensure that they have disabled the base eslint indentation rule for them (in case it was turned on via something like eslint-config-airbnb).

Copy link
Owner Author

Choose a reason for hiding this comment

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

in particular for the second point. There are three possible cases:

  1. Don't disable indent, don't turn on typescript/indent.
    • If they apply the airbnb config, then ours, and we don't disable indent, then they'll get a number of incorrect indentation errors due to the incorrect support of TS nodes. This could possibly lead to users opening issues because of the incorrect handling from the base rule.
  2. Disable indent, don't turn on typescript/indent.
    • This is terrible because it means the user will lose their indentation errors, and they mightn't even know we disabled them.
  3. Disable indent, turn on typescript/indent.
    • Stops users using the broken rule, and starts flagging errors. User knows the rule is misconfigured for their code, and adjusts accordingly.

Looking at some stats - of the top 292 starred TS repos; 45% use 4 spaces, 36% use 2 spaces, and 16% use tabs (0.68% uses 3 spaces - wtf).
So with this setting we're likely targeting the most common use case.

Copy link

@aladdin-add aladdin-add Jan 3, 2019

Choose a reason for hiding this comment

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

  1. Disable indent, turn on typescript/indent.

it has a small fault: we could disable indent for ts files, but not js files. (given some repos mixed using js and ts)

another way might be considered is Don't disable indent, don't turn on typescript/indent, but give users a guid to disable indent explicitly:

{
    "extends": ["plugin:typescript/recommended"]
     "rules": {indent: "off"}
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't have any data, but my gut would say that the majority use case is TS only. For those that have a mixed codebase, they're probably advanced enough users that they can apply overrides themselves (not that they need to, typescript/indent works fine with plain JS code).

Turning off the base rule is listed as part of the config in the docs for our indent rule..

I don't like the idea of only disabling indent, whether it be on everything, or just TS(X) files, because unless a user interrogates the recommended config, they won't know we disabled it, and could then fall into using inconsistent indent when they thought their linter was working.

Copy link
Contributor

@armano2 armano2 Jan 3, 2019

Choose a reason for hiding this comment

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

what's about vue files? more and more ppl is moving to typescript :)
vue + ts + eslint
if you limit it to ts only it's going to stop working for them

Choose a reason for hiding this comment

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

well, I was sold! 😄 @bradzacher

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.

5 participants