Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

New feature: lint js files #1515

Merged
merged 20 commits into from
Nov 3, 2016
Merged

New feature: lint js files #1515

merged 20 commits into from
Nov 3, 2016

Conversation

YuichiNukiyama
Copy link
Contributor

@YuichiNukiyama YuichiNukiyama commented Aug 25, 2016

Related issue

Fixes #515

Usage

I add jsRule option to tslint.json. We can distinguish the rules that apply to js or ts depending on this option.

{
    "jsRule": {
        "class-name": true
    }
}

Good point

  • simple implimentation
  • this is not breaking change
  • It easier to distinguish the rules that apply to js or ts

Bad point

  • There is no way to tell each rules which file(ts or js) call them
  • There is a rule that can not be applied to js (ex. arrow-parens rule can't apply js files)
  • The greater the overlap in the configuration file in some cases

Note

Now, I test only class-name and curly rule. If you think this PR is good, I add tests for another rules.

@palantirtech
Copy link
Member

Thanks for your interest in palantir/tslint, @YuichiNukiyama! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

@jkillian
Copy link
Contributor

@YuichiNukiyama What do you think of a system where each rule has metadata that's something like typescriptOnly: false? We could still keep jsRules, but that would only be as an override. By default TSLint would use all the settings in rules when linting JS files if no configuration is specified in jsRules.

@YuichiNukiyama
Copy link
Contributor Author

@jkillian Metadata is good idea. But I won't use all the settings in rules when there is no jsRules option. A lot of developer use other linter for linting js. So we should use unobtrusive setting. If they don't specified any settings in jsRule, We lint nothing.

@jkillian
Copy link
Contributor

jkillian commented Sep 1, 2016

@YuichiNukiyama But why would they pass their .js files to TSLint if they were linting them with another tool? It seems to me that if they provide .js files, they should get linted with the regular rules unless they opt-out by overriding a setting in jsRules

@YuichiNukiyama
Copy link
Contributor Author

@jkillian You've given a misunderstanding ,because of my poor english. Since the TypeScript-only rule is large, the error occurs frequently when we apply the all rule options. And now many developer use eslint to lint js files. I afraid that these developer apply the jslint to js.

@jkillian
Copy link
Contributor

jkillian commented Sep 2, 2016

Let's look at a concrete example to see what makes the most sense.

Say we start with this configuration. We then automatically skip any rules that only make sense for TS. For example, typedef-whitespace and no-namespace. We then, by default, apply the remaining rules to JS files being linted.

Are you saying that this wouldn't work well because a lot of the remaining rules wouldn't work correctly on JS files?

@YuichiNukiyama
Copy link
Contributor Author

@jkillian I add tests for all rules.
We can use following rules (sorry for my large commit).

  • alignRule
  • banRule
  • classNameRule
  • curlyRule
  • eoflineRule
  • fileHeaderRule
  • forinRule
  • indentRule
  • jsdocFormatRule
  • labelPositionRule
  • labelUndefinedRule
  • linebreakStyleRule
  • maxFileLineCountRule
  • maxLineLengthRule
  • newParensRule
  • noArgRule
  • noBitwiseRule
  • noConditionalAssignmentRule
  • noConsecutiveBlankLinesRule
  • noConsoleRule
  • noConstructRule
  • noDebuggerRule
  • noDefaultExportRule
  • noDuplicateKeyRule
  • noDuplicateVariableRule
  • noEmptyRule
  • noEvalRule
  • noForInArrayRule
  • noInvalidThisRule
  • noNullKeywordRule
  • noReferenceRule
  • noShadowedVariableRule
  • noStringLiteralRule
  • noSwitchCaseFallThroughRule
  • noTrailingWhitespaceRule
  • noUnreachableRule
  • noUnsafeFinallyRule
  • noUnusedExpressionRule
  • noUnusedNewRule
  • noUseBeforeDeclareRule
  • noVarKeywordRule
  • objectLiteralKeyQuotesRule
  • objectLiteralShorthandRule
  • objectLiteralSortKeysRule
  • oneLineRule
  • oneVariablePerDeclarationRule
  • onlyArrowFunctionsRule
  • orderedImportsRule
  • quotemarkRule
  • radixRule
  • restrictPlusOperandsRule
  • semicolonRule
  • switchDefaultRule
  • trailingCommaRule
  • tripleEqualsRule
  • useIsnanRule
  • useStrictRule
  • variableNameRule
  • whitespaceRule

@YuichiNukiyama
Copy link
Contributor Author

@jkillian I add JS recommendations.

@jkillian
Copy link
Contributor

Sorry @YuichiNukiyama, things have been really busy lately! @adidahiya, do you have time to weigh in on this / take a look?

@adidahiya
Copy link
Contributor

@YuichiNukiyama we should have time to review this soon, I think @nchen63 can take a look. Could you resolve the merge conflicts?

@YuichiNukiyama
Copy link
Contributor Author

@adidahiya Sure. I resolved conflict.
@nchen63 Please review my PR.

@@ -47,6 +47,7 @@ export class Rule extends Lint.Rules.AbstractRule {
},
optionExamples: ['[true, "check-space", "check-lowercase"]'],
type: "style",
typescriptOnly: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this typescript only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Rule don't work well in js.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the PR going in with this rule disabled for js since it's not that hard to add later, but I'm just curious why you think it doesn't work well with js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this rule pass a test. Now, #1635 privent me from doing test...

@@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule {
options: null,
optionExamples: ["true"],
type: "style",
typescriptOnly: true,
Copy link
Contributor

@nchen63 nchen63 Oct 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this rule work with js also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Rule don't work well in js.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrow functions supported in es6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule {
options: null,
optionExamples: ["true"],
type: "maintainability",
typescriptOnly: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

js also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Rule don't work well in js.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also useful in es6 with the new imports

@YuichiNukiyama
Copy link
Contributor Author

@nchen63
Some of the rules don' work well in js file. If we want use these rules in js, We should fill rules itself.
But I think that isn't scope of this PR.

"trace",
],
"no-construct": true,
"no-constructor-vars": false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was renamed to no-parameter-properties

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter properties is typescript only feature. So, I removed it.

"label-position": true,
"label-undefined": true,
"max-line-length": [true, 120],
"member-access": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this ever rule make sense for JS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it's not supported in ES.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this.

"no-unused-new": true,
// disable this rule as it is very heavy performance-wise and not that useful
"no-use-before-declare": false,
"no-var-keyword": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only applies to ES6. I don't think most Javascript users will be targeting that version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this.

@nchen63
Copy link
Contributor

nchen63 commented Nov 3, 2016

Loading tslint.json that extends another config such as "recommended", won't load the base js rules. Please update extendConfigurationFile() to include them

@nchen63
Copy link
Contributor

nchen63 commented Nov 3, 2016

Also update DEFAULT_CONFIG

@YuichiNukiyama
Copy link
Contributor Author

@nchen63 I fixed configration.ts. This commit pass ci. But somewhat there is no self-confidence.(I can't test on local.)

Copy link
Contributor

@nchen63 nchen63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Thanks!

@nchen63 nchen63 merged commit fd5ae5a into palantir:master Nov 3, 2016
@YuichiNukiyama YuichiNukiyama deleted the lint_js branch November 3, 2016 04:01
@YuichiNukiyama
Copy link
Contributor Author

Thank you for your help 😊

@nchen63
Copy link
Contributor

nchen63 commented Nov 3, 2016

You're welcome. Thanks for the contribution!

@@ -31,6 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule {
options: null,
optionExamples: ["true"],
type: "functionality",
typescriptOnly: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule was deleted on the master branch because it is covered by the compiler. I'm going to delete it again; I don't want to maintain it just for JS files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was removed in next, but not in master

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants