-
-
Notifications
You must be signed in to change notification settings - Fork 75
False positive on no-undef
with mixed JS & TS codebase
#416
Comments
no-undef
with Mixed JS & TS codebaseno-undef
with mixed JS & TS codebase
problem also appears on enumarations like here:
Error: and Error: |
Also happening here. Basically everything in this gets flagged type item = string;
type row = item[];
type doc = row[];
enum header_mode {
none = 'none',
index = 'index',
number = 'number',
first = 'first'
}
enum quoting_circumstance {
minimal = 'minimal',
always = 'always',
except_numbers = 'except_numbers',
strict_nl = 'strict_nl'
}
interface stringify_options {
headers? : row | false,
quoter? : (s: string) => string,
field_separator? : string,
row_separator? : string,
trailing_row_separator? : boolean
// , consumer: function
}
export { item, row, doc, header_mode, quoting_circumstance, stringify_options }; As so:
C:\Users\john\projects\csv_4180\src\ts\csv_types.ts
|
Let's keep in mind this is easily fixable if your code is Typescript only, since you can boldly disable this core rule as the TS compiler should complain anyway about a missing definition of something :) It really only becomes an issue when you want to take care of JS code using the same lint config. |
unless you want the actual protection afforded by the rule, which is significant |
hm, i must be missing something then :) what missing protection do you mean? when compiling actual typescript, the compiler will fail on accessing any symbol hat is "not defined" in the ecmascript sense :) so that protection from undefined symbols is basically ensured for any typescript code. the problem only occurs for code that is plain JavaScript (which the ts compiler also can process, but it will not apply the typescript compilation rules to it). for example, in a proper typescript file, if you try to assign a variable like this:
... but maybe i am just completely missing what you're trying to say or confused about something? |
@StoneCypher You can run eslint once against all .js files in your project and then again with the TS parser against all .ts files Also the TS compiler also catches undefined in JS files not just TS files |
Running this eslint config against a mixed codebase with success: module.exports = {
rules: {
// ... your js rules ...
},
overrides: {
files: ['**/*.ts'],
parser: 'typescript-eslint-parser',
rules: {
'no-undef': 'off'
}
}
} |
that's a very nice workaround 👍 |
Worth mentioning that |
for the record that "workaround" just means you can't inherit any inferred type knowledge from js into ts |
We're running |
@lvivski Yes. But Typescript compiler will already complain if you use something that is not defined, so the lint rule shouldn't be needed anyway :) |
@StoneCypher Can you give an example of what you mean? |
@tchakabam When we use babel as a compiler, it doesn't complain like typescript compiler would :/ So this rule is still usefull |
@christophehurpeau Ok. EDIT: It was completely new to me that Babel has a preset for Typescript. If it doesn't "complain" like the Typescript compiler does, what does it actually do? :) |
It just deletes the TS syntax. |
I use a lot of babel plugins like some of babel-minify or babel-plugin-discard-module-references, so I can't build with typescript. |
Sure, I have seen how one can get very integrated with Babel :) A lot of the stuff those plugins do can be done by bare webpack plugins btw, which are not tied to one or another compiler. Just in case you seek to break out. You probably should at least use it as a linter, like you propose. Writing typescript code without actually running the compiler is ... ? :) Stays that with an editor like VS Code you still get the whole Typescript-compile messages/warnings and intellisense. Is that what your current use-case is? |
It looks like this issue has been resolved and the discussion has gotten off topic. Can we close this now or is there something else being proposed? |
@kaicataldo - I'm running Babel7 and TypeScript plugin and getting this :(.
which reports:
|
* Update: add proper scope analysis (fixes #535) * add computed-properties-in-type fixture * add computed-properties-in-interface fixture * add function-overload fixture * add method-overload fixture * add class-properties fixture * add decorators fixture * update visitor-keys * add declare-global fixture * fix typo * add test for typeof in array destructuring * add namespace fixture * add declare-module fixture * fix crash * add declare-function.ts fixture * add abstract-class fixture * add typeof-in-call-signature fixture * add test for #416 * add test for #435 * add test for #437 * add test for #443 * add test for #459 * add test for #466 * add test for #471 * add test for #487 * add test for #535 * add test for #536 * add test for #476 * fix test to use `expect()`
What version of TypeScript are you using?
2.6.1
What version of
typescript-eslint-parser
are you using?11.0.0
What code were you trying to parse?
What did you expect to happen?
No lint error
What happened?
False positive on
no-undef
eslint core rule.It basically means we can not use type definitions without disabling that rule (globablly or locally)
This has already been discussed in #77
It really becomes tricky when the project mixes JS and TS code.
But we haven't found any viable solution yet, apart applying different configuration to the various file types.
It would be nice if the eslint core rules would be overridable by the Typescript parser usage somehow I guess.
BUT this is really only an issue for mixed JS/TS codebases, because:
The text was updated successfully, but these errors were encountered: