-
-
Notifications
You must be signed in to change notification settings - Fork 75
Discussion: Extending core ESLint rules to "just work" with TS-specific nodes #77
Comments
I would also like to point out that in spite of the above, I am running over 100 of the core ESLint rules on the large TypeScript codebase without any problems at all! 🎉 |
Thanks for doing this! I'm low on energy, so probably will dig in more next week. Off the top of my head, I think we can make For |
No problem at all! Just reply whenever you can.
I cannot say that I have ever thought about it (I personally use no semi-colons, regardless of JavaScript or TypeScript), but I feel like it would be limited to a subset. I will look into submitting a PR to eslint for the |
Part of what I'm wondering is if things like the |
There is no reference to semi-colons in the language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md I have asked the TypeScript team here: microsoft/TypeScript#10730 |
@nzakas It seems like it might be worth doing it for just the type alias (e.g. From Mohamed on the TS Team:
So, coming back to your suggestion:
That would be an update to the core rule right? Not an AST (and therefore parser) change? |
@JamesHenry what I meant was, we change what the parser output so that the type alias declaration outputs a Basically, |
Ah gotcha! Yeah let's give that a go as a first step |
This is great, awesome job @JamesHenry! |
@JamesHenry nice work on the type aliases, I think treating them as a special kind of variable declaration makes sense - since it's very similar syntacticly. Not sure if you have a list of TS-specific constructs you're testing, but a couple more worth checking if they need special treatment: Module declarations, for example shorthand ambient module declarations:
Type guards:
The non-null assertion operator:
Typed usages of
I don't think any of these will cause too big of issues, and some of them are relatively new TS features, but wanted to throw them out there as things to watch out for! |
Thanks a lot, @jkillian! Those will all make great test cases for full TypeScript 2 support. I will be prioritising that as soon as it is "final/stable" |
@jkillian can you paste those into a new issue for TypeScript 2 support? I'm afraid they'll get lost if left here. |
no-unused-vars is reporting an issue when you import an interface. Don't see that in the list anywhere. @JamesHenry any timeframe on when this plugin will work with "extends": "eslint:recommended"? days/weeks/months. |
@trainerbill I am back from vacation now, and this project is one of my top priorities outside of work. Thanks, interfaces and There have a been a number of wider topics to tackle within the wider ESLint ecosystem which affect this project, so it is difficult to estimate at this stage. Once they are nailed down, you will suddenly see a load of progress all at once. As I mention above, I am already using it on a large project with 100+ standard rules active. |
@trainerbill interfaces being marked as used is handled here: bradzacher/eslint-plugin-typescript#9 |
@JamesHenry I see that 1.0 was released. Just wondering if no-undef and no-unused-vars have been fixed. I have quite a few and spot checking them look like most are false negatives. Is there an ongoing list of work in progress items so we know what to submit as issues should we find one. Appreciate all you are doing here. |
@trainerbill I have been really stretched on other things over the last few weeks, but things should improve as we hit the holiday break. We moved to v1 purely because we are following semver and the support (and requirement) for TS 2 was a breaking change. Specifically in the case of Set the following flags to true when running the CLI or in your tsconfig.json
|
@JamesHenry awesome. did not know that existed in the compiler. Thanks! |
|
I'm a little confused about the current status of TS support. I planning the conversion an existing ES2016 codebase to TS, initially with minimal changes except for:
constructor(public name: string) {
} instead of constructor(name: string) {
this.name = name;
} As a test, I copied the existing "parser": "typescript-eslint-parser", I then created a simple /* A comment */
export default class Foo {
constructor(public name: string) {
}
get greeting() : string {
return `Hello ${this.name}`;
}
} As expected, linting this file encounters similar issues to the ones listed at the top of this thread:
I noticed this comment later in the thread:
So I installed "parser": "typescript-eslint-parser",
"plugins": [
"typescript"
], …but the same errors still occur. Have I misunderstood what Versions used are:
|
Ah, it looks like I may need to explicitly enable the |
@scottohara The typescript plugin rule |
i have a tiny test case for three const p = require('typescript-eslint-parser')
const { SourceCode, CLIEngine, linter } = require('eslint')
const filename = 'test.ts'
const code = `
interface Iface {
prop?: (par: string) => void
}
`
const ast = p.parse(code, { tokens: true, comment: true })
const sc = new SourceCode(code, ast)
const cli = new CLIEngine({
useEslintrc: false,
parser: 'typescript-eslint-parser',
parserOptions: { sourceType: 'module' },
rules: { 'no-undef': 1 },
})
const config = cli.getConfigForFile(filename)
const messages = linter.verify(sc, config, { filename })
console.log(messages) |
I don't experience a problem with |
At least with the example in the issue description, my experiments show that |
Another option would be to add a checklist ( |
This issue is very outdated and potentially confusing to new users so I am going to close it. Please feel free to open new issues for anything which you feel has not been addressed yet. |
@JamesHenry is it worth filing a new issue for Or is this something more appropriately handled by For now, I have turned off these two rules in my Example: export default class Foo {
constructor(private name: string) {}
get greeting() : string {
return `Hello ${this.name}`;
}
}
Edit: Created as #418 |
Typescript itself now tests for unused member properties, so for I think you can conditionally turn on the rule for (impl: eslint/eslint#8081 and eslint/eslint#7177) |
Sure, but this issue was originally about ESLint rules "just working" with TS-nodes; and clearly that's not the case yet for I don't think configuring glob patterns to workaround this satisfies the original intent of "just works". |
Fair point!
…On Mon, Dec 11, 2017 at 2:14 PM scottohara ***@***.***> wrote:
Sure, but this issue was originally about ESLint rules "just working" with
TS-nodes; and clearly that's not the case yet for no-useless-constructor
/ no-empty-function.
I don't think configuring glob patterns to workaround this satisfies the
original intent of "just works".
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#77 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAChnRgDnEybhfvbFVD8bEE7XXSpEnJ1ks5s_albgaJpZM4Jy-yV>
.
|
@JamesHenry I have created a seperate issue about the problem in mixed codebases with the |
@tchakabam Thanks for clearing that up for me. 😁 I've sent a PR to update the README but haven't followed commit guidelines correctly. I'll fix that. #440 |
Anyone know what the status of this is? I'm running into the issue where ESLint will throw |
In agreement with @nzakas, I wanted to start a discussion here which summarises the findings so far on which core ESLint rules currently have issues with TypeScript-specific concepts, such as interfaces and decorators.
We do have a few options open to us with regards to making this all work (and the
eslint-plugin-typescript
plugin will still have its place regardless), but we are in agreement that it would be awesome if we did not have to duplicate any existing rules where all we are trying to do is match the same functionality as on standard JS nodes.I have been running all of the core rules over a large TypeScript codebase (definitely not an exhaustive use of TypeScript features in there, but it's a great start) and noted the following, some of which is fairly subjective:
Rule:
camelcase
We have the ability to control whether or not
camelcase
will apply to object properties, e.g.Opinion: We should be able to do this for TypeScript interfaces properties too
Rule:
keyword-spacing
We can enforce spaces before and after keywords like so:
Opinion: We should be able to make type "casting" exempt from this in some way
E.g. I had this example:
...where I would not want to put a space between the
>
andthis
keyword, but the rule naturally wants me to.Rule:
no-undef
With TypeScript, we are supporting class properties and interfaces. These are both causing false negatives with
no-undef
:It is very likely there are more TypeScript features that will cause the same, but currently those two are so noisy in my codebase that it is not worth investigating further.
This was also reported here: #75
Rule:
no-used-vars
There are a couple of things causing false negatives with
no-unused-vars
:(1) Class properties created via the constructor, and then later used in a method
(2) Decorators
This was also reported here: #55
Rule:
no-useless-constructor
Using the same class property assignment within a constructor example from above, we will also get a false negative on
no-useless-constructor
Rule:
space-infix-ops
This rule is basically unusable, given the type annotation syntax
:
Rule:
semi
It was pointed out here #61 (comment) that TypeScript-only statements will currently not be detectable as needing a semi-colon.
E.g.
The text was updated successfully, but these errors were encountered: