tslint-consistent-codestyle icon indicating copy to clipboard operation
tslint-consistent-codestyle copied to clipboard

naming-conventions: question - recognize if variable is primitive

Open bartekleon opened this issue 5 years ago • 1 comments

I would like to have different styles for exported primitives and objects. It is possible to be done?

It should look like:

export const PRIMITIVE_VARIABLE = 12;
export const objectVariable = {
   someProps: 12
   .
   .
   .
}
export const functionVariable = () => {}

I would be grateful for any idea about it

my current config looks like:

"naming-convention": [
  true,
  { "type": "default", "format": "camelCase", "leadingUnderscore": "forbid", "trailingUnderscore": "forbid" },
  { "type": "variable", "modifiers": ["global", "const"], "format": ["camelCase"] },
  { "type": "variable", "modifiers": ["export", "const"], "format": "UPPER_CASE" },
  { "type": "functionVariable", "modifiers": ["export", "const"], "format": "camelCase" },
  { "type": "parameter", "modifiers": "unused", "leadingUnderscore": "allow" },
  { "type": "member", "modifiers": "private", "leadingUnderscore": "forbid" },
  { "type": "member", "modifiers": "protected", "leadingUnderscore": "forbid" },
  { "type": "method", "filter": "^toJSON$", "format": null },
  { "type": "property", "modifiers": ["public", "static", "const"], "format": "camelCase" },
  { "type": "type", "format": "PascalCase" },
  { "type": "class", "modifiers": "abstract", "prefix": "" },
  { "type": "interface", "prefix": "" },
  { "type": "genericTypeParameter", "prefix": "" },
  { "type": "enumMember", "format": "PascalCase" }
]

bartekleon avatar Jul 17 '19 11:07 bartekleon

This is not possible to achieve at the moment. The rule doesn't use type information and is therefore not able to tell whether a variable has a primitive type. There are several other issues that need a similar change: #1, #2, #49

I definitely think that type information would be a great addition to this rule. However, I currently have other priorities and not enough spare time to invest into this project. I'm happy to review a PR with the necessary changes if someone wants to give it a shot.

ajafff avatar Jul 17 '19 13:07 ajafff