Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

eslint-plugin-tslint is unexpectedly linting .js* files #615

Closed
joeyj-msft opened this issue Jun 14, 2019 · 7 comments
Closed

eslint-plugin-tslint is unexpectedly linting .js* files #615

joeyj-msft opened this issue Jun 14, 2019 · 7 comments
Labels
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin-tslint Issues related to @typescript-eslint/eslint-plugin-tslint

Comments

@joeyj-msft
Copy link

I started seeing linebreak-style linting failures when trying this plugin. I then realized that these were only happening for .js* files which I dont have configured in tslint.config.

tslint command (works as expected)

tslint -p .

eslint command

eslint . --ext .js,.jsx,.ts,.tsx

tslint.json (simplified)

{
  "defaultSeverity": "error",
  "extends": [
    "tslint:all"
  ],
  "rules": {
    "linebreak-style": false
  }
}

.eslintrc.json (simplified)

{
  "plugins": [
    "@typescript-eslint/tslint"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "rules": {
    "linebreak-style": [ "error", "windows" ],
    "@typescript-eslint/tslint/config": [ "error", {
      "lintFile": "./tslint.json"
    }]
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  }
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "downlevelIteration": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "react",
    "lib": ["es6", "dom"],
    "module": "es2015",
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "outDir": "dist",
    "paths": {
      "office-ui-fabric-react": ["node_modules/office-ui-fabric-react/lib-commonjs"],
      "msal": ["node_modules/msal/lib-commonjs"]
    },
    "plugins": [],
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "es5"
  },
  "include": [
    "src"
  ]
}

What did you expect to happen?
I'd expect .js* files to not be linted with tslint.

What actually happened?
.js* files are being linted with tslint.

Versions

package version
@typescript-eslint/eslint-plugin-tslint 1.10.2
@typescript-eslint/parser 1.10.2
TypeScript 3.5.2
ESLint 5.16.0
node 10.15.3
npm 6.9.0
@joeyj-msft joeyj-msft added package: eslint-plugin-tslint Issues related to @typescript-eslint/eslint-plugin-tslint triage Waiting for maintainers to take a look labels Jun 14, 2019
@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party working as intended Issues that are closed as they are working as intended and removed triage Waiting for maintainers to take a look labels Jun 14, 2019
@bradzacher
Copy link
Member

We avoid doing special filename casing in our rules because it limits people's setups and can make it impossible for some people to use our tooling.

This isn't usually a problem because generally people aren't in a state where they are transitioning from JS to TS (i.e. have both in their codebase), whilst using tslint, whilst migrating to eslint using our tslint bridge plugin.


To prevent the rules from running on your js files - you can specify overrides for specific paths/extensions using the overrides section in your eslint config.
https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files

@joeyj-msft
Copy link
Author

I applied the overrides for .js to turn off the tslint/config rule.

Could we change this into a doc bug instead?

tslint won't lint .js* files unless it is explicitly enabled and this behavior change will be confusing to new eslint users (like me) who are attempting to move all of our repos to eslint :)

@bradzacher
Copy link
Member

happy to take a PR to do that!
love new contributors.

@bradzacher bradzacher added documentation Documentation ("docs") that needs adding/updating and removed awaiting response Issues waiting for a reply from the OP or another party working as intended Issues that are closed as they are working as intended labels Jun 14, 2019
@joeyj-msft
Copy link
Author

Also, there is a bug here since I have the rule explicitly disabled and it's not being respected for .js files :( I couldn't find a way to get this to work.

@bradzacher
Copy link
Member

This config should do what you want it to unless I'm mistaken:

{
  "overrides": [
    {
      "files": ["*.ts", "*.tsx"],
      "rules": {
        "@typescript-eslint/tslint/config": ["error", {
          "lintFile": "./tslint.json"
        }]
      }
    }
  ]
}

@joeyj-msft
Copy link
Author

I have it disabled for .js instead. I would like to run some of the rules against .js files but I can't get the plugin to respect the config for .js files in tslint.config. My example config above shouldn't give errors for CRLF line endings but it does (only in .js files):

error  Expected linebreak to be 'LF' (tslint:linebreak-style)`                                                          @typescript-eslint/tslint/config

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin-tslint Issues related to @typescript-eslint/eslint-plugin-tslint
Projects
None yet
Development

No branches or pull requests

2 participants