-
Notifications
You must be signed in to change notification settings - Fork 63
add a recommended preset #144
Comments
Can anyone share the typescript rules they're using? Do you just copy/paste from the README and set them all to 'error'? |
I'm also unclear about usage. Should all of these rules be enabled and then have select core ESLint rules to enable, or do these replace them (except for no-unused-vars)? |
Im using this tslint recommendation aligned configuration:
|
I did some homework: https://www.npmjs.com/package/eslint-config-typescript-recommended Maybe it could be integrated into this plugin. :-) |
@ChristianStornowski a quick note: |
Thanks for this hint. :-) If i'm reading this correct: https://eslint.org/docs/rules/valid-jsdoc#options i only have to set |
I'm the owner of eslint-config-typescript and my intention was (and still is) to complement this project with that one... I'm willing to work with anyone that is interested in making that happen 😄 |
They are different projects in the npm world: https://www.npmjs.com/package/eslint-config-standard-with-typescript we should combine them together. The question is who should be the owner. Should be eslint-plugin-typescript the owner for this configs? |
Re: combining them together I am the person behind https://www.npmjs.com/package/eslint-config-standard-with-typescript. I don't see a good reason for combining them together. Further, I feel that recommendations should be outside the scope of this project. Let the community provide shareable configs, is how I see it. I would close this issue. |
Definitely add them to the README though 👍 |
It's common practice for plugin authors to provide at the very least a "recommended" config set, if not more than that [1] [2] [3] [4] The idea is to ease adoption of the plugin: i.e. "I like the idea of linting [react/typescript/jest/etc], but I don't want to read the docs and configure each rule myself, I'll start with the recommended and then tweak based on what I love/hate". We'll definitely be looking to add at least a recommended config; we'll review the community (i.e. all of your) configs and figure out what is the best recommendation. Aim will be to have this in for the 1.0.0 release. |
(copying comment from #204 (comment) for visibility) I went through 4 configs that I know with config for our plugin, and came up with the following recommendations by merging them together. Please provide feedback. The configs for reference, with keys sorted:eslint-config-typescript-recommended
https://github.com/diva-e/eslint-config-typescript-recommended/blob/master/index.js#L124-L140 {
"typescript/adjacent-overload-signatures": "error",
"typescript/class-name-casing": "error",
"typescript/explicit-member-accessibility": "error",
"typescript/interface-name-prefix": ["error", "always"],
"typescript/member-ordering": "error",
"typescript/no-angle-bracket-type-assertion": "error",
"typescript/no-empty-interface": "error",
"typescript/no-explicit-any": "off",
"typescript/no-namespace": "error",
"typescript/no-parameter-properties": "off",
"typescript/no-triple-slash-reference": "error",
"typescript/no-type-alias": "error",
"typescript/no-var-requires": "error",
"typescript/prefer-namespace-keyword": "error"
} eslint-config-typescript
https://github.com/weirdpattern/eslint-config-typescript/blob/master/src/typescript.js#L21-L68 {
"typescript/adjacent-overload-signatures": "error",
"typescript/class-name-casing": "error",
"typescript/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
],
"typescript/explicit-member-accessibility": "error",
"typescript/interface-name-prefix": "error",
"typescript/member-delimiter-style": "error",
"typescript/member-ordering": [
"error",
{
"default": [
"static-field",
"private-field",
"protected-field",
"public-field",
"constructor",
"public-method",
"protected-method",
"private-method"
]
}
],
"typescript/no-angle-bracket-type-assertion": "error",
"typescript/no-array-constructor": "error",
"typescript/no-inferrable-types": [
"error",
{
"ignoreProperties": true,
"ignoreParameters": true
}
],
"typescript/no-namespace": [
"error",
{
"allowDeclarations": true
}
],
"typescript/no-non-null-assertion": "error",
"typescript/no-parameter-properties": "error",
"typescript/no-triple-slash-reference": "error",
"typescript/no-use-before-define": "error",
"typescript/no-var-requires": "error",
"typescript/prefer-namespace-keyword": "error",
"typescript/type-annotation-spacing": "error"
} eslint-config-standard-with-typescript
https://github.com/mightyiam/eslint-config-standard-with-typescript/blob/master/src/index.ts#L19-L32 {
"typescript/adjacent-overload-signatures": "error",
"typescript/explicit-function-return-type": "error",
"typescript/explicit-member-accessibility": "error",
"typescript/member-delimiter-style": [
"error",
{
"delimiter": "none"
}
],
"typescript/no-angle-bracket-type-assertion": "error",
"typescript/no-array-constructor": "error",
"typescript/no-empty-interface": "error",
"typescript/no-namespace": "error",
"typescript/no-non-null-assertion": "error",
"typescript/no-triple-slash-reference": "error",
"typescript/no-unused-vars": "error",
"typescript/no-use-before-define": [
"error",
{
"functions": false,
"classes": false,
"variables": false,
"typedefs": false
}
],
"typescript/no-var-requires": "error",
"typescript/type-annotation-spacing": "error"
}
eslint-config-assignar
This is the last company I worked at, and I did the eslint config :) {
"typescript/adjacent-overload-signatures": "error",
"typescript/class-name-casing": "error",
"typescript/explicit-function-return-type": "off",
"typescript/explicit-member-accessibility": "error",
"typescript/interface-name-prefix": ["warn", "never"],
"typescript/member-delimiter-style": [
"error",
{
"delimiter": "none",
"requireLast": true,
"ignoreSingleLine": true
}
],
"typescript/member-naming": "off",
"typescript/member-ordering": "off",
"typescript/no-angle-bracket-type-assertion": "error",
"typescript/no-array-constructor": "error",
"typescript/no-empty-interface": "off",
"typescript/no-explicit-any": "warn",
"typescript/no-inferrable-types": "off",
"typescript/no-namespace": [
"error",
{
"allowDeclarations": false,
"allowDefinitionFiles": true
}
],
"typescript/no-non-null-assertion": "warn",
"typescript/no-parameter-properties": "error",
"typescript/no-triple-slash-reference": "warn",
"typescript/no-type-alias": "off",
"typescript/no-unused-vars": "error",
"typescript/no-use-before-define": "error",
"typescript/no-var-requires": "off",
"typescript/prefer-namespace-keyword": "off",
"typescript/type-annotation-spacing": [
"error",
{
"before": false,
"after": true,
"overrides": {
"arrow": {
"before": true,
"after": true
},
"colon": {
"before": false,
"after": true
}
}
}
]
} Recommended Config{
"typescript/adjacent-overload-signatures": "error",
"typescript/array-type": ["error", "array"],
"typescript/ban-types": [
"error",
{
"types": {
"Boolean": {
"message": "Use boolean instead",
"fixWith": "boolean"
},
"Number": {
"message": "Use number instead",
"fixWith": "number"
},
"Object": {
"message": "Use Record<string, any> instead",
"fixWith": "Record<string, any>"
},
"Symbol": {
"message": "Use symbol instead",
"fixWith": "symbol"
}
}
}
],
"typescript/camelcase": [
"error",
{
"allow": ["^UNSAFE_"],
"ignoreDestructuring": false,
"properties": "never"
}
],
"typescript/class-name-casing": "error",
"typescript/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
],
"typescript/explicit-member-accessibility": "error",
"typescript/generic-type-naming": ["error", "'^T[A-Z][a-zA-Z]+$'"],
"indent": "off",
"typescript/indent": ["error", 4],
"typescript/interface-name-prefix": ["error", "never"],
"typescript/member-delimiter-style": "error",
"typescript/member-ordering": "error",
"typescript/no-angle-bracket-type-assertion": "error",
"typescript/no-array-constructor": "error",
"typescript/no-empty-interface": "error",
"typescript/no-explicit-any": "error",
"typescript/no-inferrable-types": [
"error",
{
"ignoreProperties": true,
"ignoreParameters": true
}
],
"typescript/no-misused-new": "error",
"typescript/no-namespace": [
"error",
{
"allowDeclarations": true
}
],
"typescript/no-non-null-assertion": "error",
"typescript/no-object-literal-type-assertion": "error",
"typescript/no-parameter-properties": "error",
"typescript/no-triple-slash-reference": "error",
"typescript/no-type-alias": "off",
"no-unused-vars": "off",
"typescript/no-unused-vars": "off",
"typescript/no-use-before-define": "error",
"typescript/no-var-requires": "error",
"typescript/prefer-interface": "error",
"typescript/prefer-namespace-keyword": "error",
"typescript/type-annotation-spacing": "error"
} |
@bradzacher is typescript/no-unused-vars supposed to be off? Just a few thoughts that are totally my personal opinion
|
@corbinu For the angle bracket type assertion, I think the |
@j-f1 guess maybe it just looks natural to me as Java was the second language I learned so casting just looks like that to me ;) and also because I started in TypeScript so early when this was the only option. Either way I do think that the recommended settings should favor conforming to how typescript programmers currently format their code rather than be prescriptive as that will most likely hurt adoption. A lot of large old TypeScript projects still use the bracket format. Plus if they want a more prescriptive format that is kinda what Prettier is for in my mind. |
recomended configuration should be default one set in rule, that user is not forced to setup configuration to make it work, for example: "typescript/no-namespace": [ "error", {
"allowDeclarations": true
}],
|
Note that Prettier doesn’t prescribe a style here — its goal is to print the syntax as-is without changing it. |
@j-f1 guess we will have to disagree here I am basing this on prettier's "An opinionated code formatter" from their docs. I feel like that is not the goal of prettier even if it is not the current behavior of prettier |
Probably best for us to turn it on as a warning then?
Being an experienced TS dev; I personally prefer it on, but on as a warning. If only so that other devs on my team are less likely to use any 😄. I'm of the opinion that using
From what I've seen in the docs that the TS team releases, using I came from a java/c++/c# background, but I much prefer the as syntax anyways; much easier to follow.
I just copy pasted the regex. But in an ideal world you should probably name your generics with more than just I'm not sure if that should be there though... is that considered an anti-pattern in TS now? (similar to how @armano2 Yeah we'll figure out what our defaults are with this recommended set, and we'll make the changes across the board to match. |
Maybe we should considering palantir/tslint#1142. There are a lot of discussions and implementation https://github.com/palantir/tslint/commits/master to be more aligned with https://www.npmjs.com/package/tslint-microsoft-contrib. |
@bradzacher Thanks for the feedback makes sense as for the "best practice" types of rules I have seen a lot of eslint packages have both an "essential" config that doesn't include them and then a "recommended" that does. |
See #261 |
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 #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.
@bradzacher I have started using this however I am getting errors that the recommended config sets some rules as "warning" instead of "warn" for example "typescript/explicit-function-return-type" |
@j-f1 Thanks! |
No description provided.
The text was updated successfully, but these errors were encountered: