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

Excludes for variable-name #522

Closed
Anahkiasen opened this issue Jul 22, 2015 · 12 comments
Closed

Excludes for variable-name #522

Anahkiasen opened this issue Jul 22, 2015 · 12 comments

Comments

@Anahkiasen
Copy link

I have a variable in my app that comes from a third party and needs to be named a certain way. Would it be possible to add the ability to exclude a certain variable name? Like,

"variable-name": [true,
    "TheVarName",
],

Or something like that?

@senhongo
Copy link

You can insert rule exclusions in your code using comments

/* tslint:disable: name-of-rule-to-disable */
yourCodeHere
/* tslint:enable */

@Anahkiasen
Copy link
Author

Yes but in my case it's a service I import in multiple controllers and I don't want to litter my codes with comments like that, it would be way easier to ignore it globally. If the syntax is the issue then maybe an object (which would be clearer anyway than the array thing used currently):

"variable-name": {
  enabled: true,
  ignore: ['TheVarName'],
},

@adidahiya
Copy link
Contributor

What's the exact code this rule is failing on? Are you re-declaring the variable? If it's provided by a third party library, shouldn't it be declared outside of the code you're linting?

@Anahkiasen
Copy link
Author

It's an Angular service I'm injecting so the variable name has to match the service name registered on the container by the third party

@adidahiya
Copy link
Contributor

ah, ok. This is similar to #457. Do you have use cases where the injected variable is used as something other than a constructor? Meaning, if we resolve #457, would that satisfy your use case completely?

@Anahkiasen
Copy link
Author

Hm I think it might, not sure, it's a factory. Here's my code dumbed down:

class MyClass {
  constructor(public Flash: Flash) {}

  someMethod() {
    this.Flash.create('success', 'The message');
  }
}

@adidahiya
Copy link
Contributor

Even with #577 implemented, that still doesn't address variables from third party libs which are declared as interfaces instead of classes. So I agree we should implement excludes for the variable-name rule.

@ajcrites
Copy link
Contributor

Another example of when this comes up is using stateless functional components in react.

export const Example: React.SFC<{}> = () => <div />;

With the current rule, this variable name doesn't pass the lint check, but React requires that custom components including SFCs be capitalized.

ajcrites added a commit to ajcrites/ts-config-mobiquity that referenced this issue Feb 12, 2018
@ChrisSG
Copy link

ChrisSG commented Jun 11, 2018

The SFC is what hits us at the moment. I think that maybe only classnames should be PascalCase and one should explicitely do it like this:

const example = ...

export {example as Example}

Any more thoughts on this?

@joshghent
Copy link

We have also run into this issue at my work place, we do not use snake_case variables but have multiple data base columns that are snake_case and therefore violate the rules. The solution outlined in the original post (or something similar) would solve this for us because we know exactly what we want to allow.

@JoshuaKGoldberg
Copy link
Contributor

☠️ TSLint's time has come! ☠️

TSLint is no longer accepting most feature requests per #4534. See typescript-eslint.io for the new, shiny way to lint your TypeScript code with ESLint. ✨

It was a pleasure open sourcing with you all!

@JoshuaKGoldberg
Copy link
Contributor

🤖 Beep boop! 👉 TSLint is deprecated 👈 (#4534) and you should switch to typescript-eslint! 🤖

🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋

@palantir palantir locked and limited conversation to collaborators Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants