添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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 ? "test" : process . env . DOTENV && process . env . DOTENV . length > 0 ? process . env . DOTENV : DEFAULT_DOTENV_NAME ; const dotenvFileName = `.env- ${ dotenvName } ` ; if ( fs . existsSync ( dotenvFileName ) ) { console . info ( `Using dotenv file: ${ dotenvFileName } ` ) ; } else { console . warn ( `dot-env file not found: ${ dotenvFileName } , assuming env vars are passed manually` , return { clientAllowedKeys : [ ] , // Fail build when there is missing any of clientAllowedKeys environment variables. // By default false. failOnMissingKey : false , path : dotenvFileName ,
.eslintrc.yml

root : true parser : " @typescript-eslint/parser " parserOptions : ecmaVersion : 2018 sourceType : module # Required for `plugin:@typescript-eslint/recommended-requiring-type-checking` # which needs both browser and Node environments configured explicitly project : - " ./tsconfig.json " - " ./tsconfig-node.json " plugins : - " @typescript-eslint " - ember - prettier extends : - eslint:recommended - plugin:@typescript-eslint/eslint-recommended - plugin:@typescript-eslint/recommended - plugin:@typescript-eslint/recommended-requiring-type-checking - plugin:ember/recommended - standard - prettier/@typescript-eslint - prettier/standard # This one should come last - plugin:prettier/recommended env : browser : true rules : " @typescript-eslint/ban-ts-ignore " : off # Can't fully get rid of it due to TS quirks and issues with third-party depenecies " @typescript-eslint/camelcase " : off # Allow two levels of separation, e. g. ProductWizard_SidebarConfig_ListWithHeader_Component_Args " @typescript-eslint/class-name-casing " : off # Allow two levels of separation, e. g. ProductWizard_SidebarConfig_ListWithHeader_Component_Args " @typescript-eslint/explicit-function-return-type " : error " @typescript-eslint/no-empty-interface " : off " @typescript-eslint/no-explicit-any " : off " @typescript-eslint/no-unused-vars " : [error, {argsIgnorePattern: "^_"}] " @typescript-eslint/no-useless-constructor " : error " @typescript-eslint/unbound-method " : off camelcase : off new-cap : off no-console : [error, {allow: [warn, error, info, debug]}] no-useless-constructor : off prefer-const : error prettier/prettier : [error, {arrowParens: always, trailingComma: all}] overrides : files : - .ember-cli.js - .eslintrc.js - .template-lintrc.js - ember-cli-build.js - testem.js - blueprints/*/index.js - config/**/*.js - lib/*/index.js - server/**/*.js excludedFiles : - app/** parserOptions : sourceType : script ecmaVersion : 2015 env : browser : false node : true plugins : - node rules : " @typescript-eslint/no-var-requires " : off no-process-exit : error node/no-deprecated-api : error node/no-extraneous-require : error node/no-missing-require : error node/no-unpublished-bin : error node/no-unpublished-require : off node/no-unsupported-features/es-builtins : error node/no-unsupported-features/es-syntax : [error, {ignores: []}] node/no-unsupported-features/node-builtins : error node/process-exit-as-throw : error node/shebang : error node/no-extraneous-import : off node/no-missing-import : off node/no-unpublished-import : off extends : - plugin:node/recommended files : - tests/**/*-test.ts - tests/**/*-test.js rules : no-unused-expressions : off

tsconfig-node.json

"compilerOptions" : { "allowJs" : true , "allowSyntheticDefaultImports" : true , "alwaysStrict" : true , "baseUrl" : " . " , "experimentalDecorators" : true , "inlineSourceMap" : true , "inlineSources" : true , "module" : " es6 " , "moduleResolution" : " node " , "noEmit" : true , "noEmitOnError" : false , "noFallthroughCasesInSwitch" : true , "noImplicitAny" : true , "noImplicitReturns" : true , "noImplicitThis" : true , "noUnusedLocals" : true , "noUnusedParameters" : true , "strictNullChecks" : true , "strictPropertyInitialization" : true , "target" : " es2017 " , "skipLibCheck" : true "include" : [ " .ember-cli.js " , " .eslintrc.js " , " .template-lintrc.js " , " ember-cli-build.js " , " testem.js " , " blueprints/*/index.js " , " config/**/*.js " , " lib/*/index.js " , " server/**/*.js "

Expected Result

No TS-specific linting errors reported for a JS file.

Actual Result

C:\Code\kaliber5\wbc\config\dotenv.js
  5:18  error  Missing return type on function  @typescript-eslint/explicit-function-return-type

Versions

package version

as per the rule's readme, and the 2.0 release notes - this is working as intended.

If you have a mixed js/ts codebase, you should use eslint overrides to disable the rule for js files.

Related: #906

I had tried overriding it the other way (allow by default, disable for .js) and failed.

I have now applied the recommended way (disable by default, enable for .ts). It works!

rules: { // disable the rule for all files "@typescript-eslint/explicit-function-return-type": "off" overrides: [ // enable the rule specifically for TypeScript files "files": ["*.ts", "*.tsx"], "rules": { "@typescript-eslint/explicit-function-return-type": ["error"]

As per the documentation, the rule in question should only be enabled on TS files. However, it is enabled on every file by default in plugin:@typescript-eslint/recommended.

Ain't this a bug that should be fixed?

Please consider reopening.

No, it is not.
This is an intentional decision.
ESLint has overrides so you can choose which files to run what rules on.
If you configure it on a js file, it'll report errors you can't fix.

The way to fix it is mentioned above.

Well, why does it intentionally apply rules to files that don't work together?

We know the rule crashes on JS files and is intended for TS files only. Why don't we apply it to TS files only?

I feel like this is The Inmates Are Running the Asylum type of situation: it was easier for maintainers to set up the plugin that way, and that's it. They cared for the convenience of their development more than the usage experience for plugin consumers.

As an end user, I can't think of a single reason why that rule should not be applied to TS files only. :/

Because we don't know your exact setup.
Restricting file extensions isn't something you do in eslint plugins because you never know what the end-user's setup is.
In particular, if we only run it on ts files (like we did before the 2.0 release), then users using markdown, or vue, or mdx, or any other file extension wouldn't be able to use the rule.

You'll find the same problems if you use eslint-plugin-jest. If you have functions called expect, it, or describe outside of a test file, you'll get weird errors. Which is why it's recommended to use overrides to specify the paths of your test files.

Or if you have a backend/frontend monorepo and you have eslint-plugin-node installed, and you don't use overrides to restrict the plugin to your server files, then you might get weird errors in your front end.

Etc, etc.

The standard for eslint is: "we don't know your environment, so configure it yourself to suit".
We clearly document it in the readme so you know about this case..

Well, my point is that your default setup is faulty and affects a huge portion of users, and the reasoning behind it that you want to protect exotic setups used by a tiny portion of users.

Why? Those elaborate setups require a deeper knowledge of eslint and typescript-eslint anyway. If you set up TS in Markdown, Vue and MDX, you won't have a problem setting up exceptions.

But every novice user who has a JS file in their codebase will stumble upon this. Every user will get frustrated, will need to google it up and adjust the config to fix the faulty defaults. 😕