Skip to content

Commit

Permalink
Expand tslint schema for three properties to address #249 (#250)
Browse files Browse the repository at this point in the history
* Expand tslint schema for member-ordering, no-consecutive-blank-lines, and no-inferrable-types. Fixes #249

* Add extra options for semicolon rule

* Fixed indenting and spacing to be consistent

* Add support for "catch-all" members without public/protected/private in front

Add support for custom member "kinds" grouped together

* Fix tests to adhere to new schema for member ordering, use examples from https://palantir.github.io/tslint/rules/member-ordering/

* Fix missing brace in tslint-test2.json.
  • Loading branch information
rikoe authored and madskristensen committed Jun 15, 2017
1 parent 992637a commit a129681
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 54 deletions.
185 changes: 145 additions & 40 deletions src/schemas/json/tslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"title": "JSON schema for the TSLint configuration files",
"$schema": "http://json-schema.org/draft-04/schema#",

Expand Down Expand Up @@ -86,9 +86,9 @@
},
"component-class-suffix": {
"description": "Enforces all components having the suffix of 'Component'",
"type": ["boolean", "array"],
"type": [ "boolean", "array" ],
"items": {
"type": ["boolean", "string"]
"type": [ "boolean", "string" ]
}
},
"component-selector-name": {
Expand Down Expand Up @@ -125,9 +125,9 @@
},
"directive-class-suffix": {
"description": "Enforces all components having the suffix of 'Directive'",
"type": ["boolean", "array"],
"type": [ "boolean", "array" ],
"items": {
"type": ["boolean", "string"]
"type": [ "boolean", "string" ]
}
},
"directive-selector-name": {
Expand Down Expand Up @@ -227,9 +227,100 @@
"member-ordering": {
"description": "Enforces chosen member ordering",
"type": "array",
"items": {
"type": [ "object", "boolean", "string" ]
}
"items": [
{
"type": "boolean"
},
{
"type": "object",
"properties": {
"order": {
"oneOf": [
{
"type": "string",
"enum": [
"fields-first",
"instance-sandwich",
"statics-first"
]
},
{
"type": "array",
"items": {
"oneOf": [
{
"type": "string",
"enum": [
"static-field",
"public-static-field",
"private-static-field",
"protected-static-field",
"static-method",
"private-static-method",
"public-static-method",
"protected-static-method",
"instance-field",
"public-instance-field",
"protected-instance-field",
"private-instance-field",
"constructor",
"public-constructor",
"protected-constructor",
"private-constructor",
"instance-method",
"public-instance-method",
"protected-instance-method",
"private-instance-method"
]
},
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"kinds": {
"type": "array",
"items": {
"type": "string",
"enum": [
"static-field",
"public-static-field",
"private-static-field",
"protected-static-field",
"static-method",
"private-static-method",
"public-static-method",
"protected-static-method",
"instance-field",
"public-instance-field",
"protected-instance-field",
"private-instance-field",
"constructor",
"public-constructor",
"protected-constructor",
"private-constructor",
"instance-method",
"public-instance-method",
"protected-instance-method",
"private-instance-method"
]
},
"maxLength": 15
}
},
"additionalProperties": false
}
]
},
"maxLength": 15
}
]
}
},
"additionalProperties": false
}
]
},
"new-parens": {
"description": "Requires parentheses when invoking a constructor via the `new` keyword",
Expand Down Expand Up @@ -257,10 +348,17 @@
},
"no-consecutive-blank-lines": {
"description": "Disallows one or more blank lines in a row",
"type": "array",
"items": {
"type": [ "boolean", "integer" ]
}
"oneOf": [
{
"type": "boolean"
},
{
"type": "array",
"items": {
"type": [ "boolean", "integer" ]
}
}
]
},
"no-console": {
"description": "Disallows access to the specified functions on console",
Expand Down Expand Up @@ -321,10 +419,17 @@
},
"no-inferrable-types": {
"description": "Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean",
"type": "array",
"items": {
"enum": [ true, false, "ignore-params" ]
}
"oneOf": [
{
"type": "boolean"
},
{
"type": "array",
"items": {
"enum": [ true, false, "ignore-params" ]
}
}
]
},
"no-internal-module": {
"description": "Disallows internal module, use namespace instead",
Expand Down Expand Up @@ -387,10 +492,10 @@
"no-unused-expression": {
"description": "Disallows unused expression statements",
"type": [ "array", "boolean" ],
"items": {
"type": [ "boolean", "string"],
"enum": [ true, false, "allow-fast-null-checks", "allow-new", "allow-tagged-template" ]
}
"items": {
"type": [ "boolean", "string" ],
"enum": [ true, false, "allow-fast-null-checks", "allow-new", "allow-tagged-template" ]
}
},
"no-unused-new": {
"description": "Disallows unused 'new' expression statements",
Expand Down Expand Up @@ -479,10 +584,10 @@
},
"semicolon": {
"description": "Enforces semicolons at the end of every statement",
"type": "array",
"items": {
"enum": [ true, false, "always", "never", "ignore-bound-class-methods", "ignore-interfaces"]
}
"type": "array",
"items": {
"enum": [ true, false, "always", "never", "ignore-bound-class-methods", "ignore-interfaces" ]
}
},
"switch-default": {
"description": "Enforces a default case in switch statements",
Expand All @@ -508,14 +613,14 @@
"type": "array",
"items": {
"enum": [
true,
false,
"call-signature",
"parameter",
"arrow-parameter",
"property-declaration",
"variable-declaration",
"member-variable-declaration"
true,
false,
"call-signature",
"parameter",
"arrow-parameter",
"property-declaration",
"variable-declaration",
"member-variable-declaration"
]
}
},
Expand Down Expand Up @@ -587,9 +692,9 @@
},
"component-class-suffix": {
"description": "Enforces all components having the suffix of 'Component'",
"type": ["boolean", "array"],
"type": [ "boolean", "array" ],
"items": {
"type": ["boolean", "string"]
"type": [ "boolean", "string" ]
}
},
"component-selector-name": {
Expand Down Expand Up @@ -626,9 +731,9 @@
},
"directive-class-suffix": {
"description": "Enforces all components having the suffix of 'Directive'",
"type": ["boolean", "array"],
"type": [ "boolean", "array" ],
"items": {
"type": ["boolean", "string"]
"type": [ "boolean", "string" ]
}
},
"directive-selector-name": {
Expand Down Expand Up @@ -909,10 +1014,10 @@
},
"semicolon": {
"description": "Enforces semicolons at the end of every statement",
"type": "array",
"items": {
"enum": [ true, false, "always", "never", "ignore-bound-class-methods", "ignore-interfaces"]
}
"type": "array",
"items": {
"enum": [ true, false, "always", "never", "ignore-bound-class-methods", "ignore-interfaces" ]
}
},
"switch-default": {
"description": "Enforces a default case in switch statements",
Expand Down
9 changes: 4 additions & 5 deletions src/test/tslint/tslint-test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"rules": {
"align": [true,
"parameters",
Expand All @@ -18,10 +18,9 @@
"jsdoc-format": true,
"max-line-length": [true, 140],
"member-access": true,
"member-ordering": [true,
"public-before-private",
"static-before-instance",
"variables-before-functions"
"member-ordering": [
true,
{ "order": "fields-first" }
],
"no-any": false,
"no-arg": true,
Expand Down
18 changes: 13 additions & 5 deletions src/test/tslint/tslint-test2.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"rules": {
"align": [true,
"parameters",
Expand All @@ -22,10 +22,18 @@
"jsdoc-format": true,
"max-line-length": [true, 140],
"member-access": true,
"member-ordering": [true,
"public-before-private",
"static-before-instance",
"variables-before-functions"
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"constructor",
"public-instance-method",
"protected-instance-method",
"private-instance-method"
]
}
],
"no-any": false,
"no-arg": true,
Expand Down
19 changes: 15 additions & 4 deletions src/test/tslint/tslint-test3.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"rulesDirectory": [ "node_modules/codelyzer" ],
"rules": {
"align": [
Expand All @@ -24,9 +24,20 @@
"member-access": true,
"member-ordering": [
true,
"public-before-private",
"static-before-instance",
"variables-before-functions"
{
"order": [
{
"name": "static non-private",
"kinds": [
"public-static-field",
"protected-static-field",
"public-static-method",
"protected-static-method"
]
},
"constructor"
]
}
],
"no-any": false,
"no-arg": true,
Expand Down

0 comments on commit a129681

Please sign in to comment.