mgechev / codelyzer

Static analysis for Angular projects.
http://codelyzer.com/
MIT License
2.45k stars 233 forks source link

[Feature request] - Generic rule to enforce prefixes/suffixes #567

Closed rafaelss95 closed 6 years ago

rafaelss95 commented 6 years ago

Currently we have rules to enforce component and directive suffixes, but Angular style guide have more rules for the other suffixes:

So I thought it's a good idea either to create a rule for everyone (IMHO not the best solution) or to create a generic rule in order to cover all cases.


A configuration schema would be:

{
  "type": "object",
  "properties": {
    "prefix": {
      "type": "string"
    },    
    "suffix": {
      "type": "string"
    }
  }
}

A standard config based on Angular style guide could be: "naming-convention": [true]

A sample of custom configuration could be:

"naming-convention": [
  true,
  { "type": "Component", "prefix": "MyPrefixLibName", "suffix": "Component" },
  { "type": "Directive", "prefix": "MyPrefixLibName", "suffix": "Directive" },
  { "type": "Injectable", "prefix": "MyPrefixLibName", "suffix": "Service" },
  { "type": "Module", "prefix": "MyPrefixLibName", "suffix": "Module" },
  { "type": "Pipe", "prefix": "MyPrefixLibName", "suffix": "Pipe" },
  { "type": "RoutingModule", "MyPrefixLibName": "Any", "suffix": "RoutingModule" }
]

... or

"naming-convention": [
  true,
  "Component": {
    "prefix": "MyPrefixLibName", "suffix": "Component"
  },
  "Directive": {
    "prefix": "MyPrefixLibName", "suffix": "Directive"
  },
  "Injectable": {
    "prefix": "MyPrefixLibName", "suffix": "Service"
  },
  "Module": {
    "prefix": "MyPrefixLibName", "suffix": "Module"
  },
  "Pipe": {
    "prefix": "MyPrefixLibName", "suffix": "Pipe"
  },
  "RoutingModule": {
    "prefix": "MyPrefixLibName", "suffix": "RoutingModule"
  }
]

Questions:


This is based on https://github.com/ajafff/tslint-consistent-codestyle/blob/master/docs/naming-convention.md#examples

mgechev commented 6 years ago

Following the feature request process that lodash has, I'm closing the issue and adding votes needed label.

Later we can prioritize the feature requests by popularity and include them in a future release.