-
Notifications
You must be signed in to change notification settings - Fork 15
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
Create a whitelist for id-length rule #40
Comments
https://github.com/Glavin001/tslint-clean-code/blob/master/src/tests/IdLengthRuleTests.ts#L89-L93 [
true,
{
exceptions: ["x", "y", "f", "c"]
}
]; https://github.com/Glavin001/tslint-clean-code/blob/master/src/tests/IdLengthRuleTests.ts#L135 [true, ["x", "y", "f", "c"]]; Does this resolve your issue? 😃 |
@Glavin001 It mostly does, thank you! I looked here and thought |
Oh, you're right! I think that's a bug in the metadata. Pull Requests welcome 😃 |
@Glavin001 From what I can see, all valid options (except for the implicit boolean at the beginning) look like this: optionExamples: [
[true],
[true, 2],
[true, ['x', 'y', 'f', 'c']],
[true, 2, ['x', 'y', 'f', 'c']],
[
true,
{
min: 2,
max: 10,
exceptions: ['x', 'y', 'f', 'c'],
},
],
], Given that model and the
I produced the following JSON schema which you can validate on-line: {
"$schema": "http://json-schema.org/draft-06/schema#",
"definitions": {
"minimum-length": {
"type": "integer",
"minimum": 1,
"default": 2
},
"maximum-length": {
"type": "integer",
"minimum": 1
},
"exceptions": {
"type": "array",
"items": {
"type": "string"
},
"minLength": 0,
"uniqueItems": true
}
},
"type": "array",
"items": {
"type": "array",
"items": {
"oneOf": [
{
"title": "Only the minimum length",
"$ref": "#/definitions/minimum-length"
},
{
"title": "Only the exceptions array",
"$ref": "#/definitions/exceptions"
},
{
"title": "Configuration object",
"type": "object",
"properties": {
"min": { "$ref": "#/definitions/minimum-length" },
"max": { "$ref": "#/definitions/maximum-length" },
"exceptions": { "$ref": "#/definitions/exceptions" }
},
"additionalProperties": false,
"minProperties": 1
}
]
},
"minItems": 1,
"maxItems": 1
}
} The schema is supposed to describe the options after that boolean. My schema works with the below model: [
[2],
[["x", "y", "f", "c"]],
[
{
"min": 2,
"max": 10,
"exceptions": ["x", "y", "f", "c"]
}
]
] but what seems to be problematic is the configuration variant in which one passes both the minumum length and exceptions: [true, 2, ["x", "y", "f", "c"]] In that situation, should the the options after that boolean be a tuple of Additionally, the version of TSLint used in the repository (5.1.0) doesn't allow to represent the /**
* Examples of what a standard config for the rule might look like.
*/
optionExamples?: string[]; The new API allows JSON-like objects: It may be necessary to upgrade TSLint in order to deliver rich rule documentation without having to cast it to |
Type assertion is required because the currently used version of TSLint expects a string[]. See Glavin001#40.
Hello and thank you for your work.
The
id-length
rule is great for forbidding one-letter variable names. However, there are cases where one-letter symbols would actually be preferred: type parameters (GenericTypeAnnotation
nodes) and holes.Holes
Type parameters
What do you think about passing a config that would allow them?
The text was updated successfully, but these errors were encountered: