eslint-plugin-ban
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -13,2 +13,60 @@ /** | ||
const SIMPLE_BAN_RULE_SCHEMA = { | ||
'type': 'object', | ||
'properties': { | ||
'name': { | ||
'type': 'string' | ||
}, | ||
'message': { | ||
'type': 'string' | ||
} | ||
}, | ||
'additionalProperties': false, | ||
'required': ['name'], | ||
}; | ||
const COMPLEX_BAN_RULE_SCHEMA = { | ||
'type': 'object', | ||
'properties': { | ||
'name': { | ||
'type': 'array', | ||
'items': [ | ||
{ 'type': 'string' }, | ||
{ 'type': 'string' } | ||
] | ||
}, | ||
'message': { | ||
'type': 'string' | ||
} | ||
}, | ||
'additionalProperties': false, | ||
'required': ['name'], | ||
}; | ||
const formalizeRule = rule => { | ||
const isArray = Array.isArray(rule.name); | ||
return isArray | ||
? rule | ||
: Object.assign({ | ||
name: [NO_OBJECT, rule.name], | ||
message: rule.message | ||
}, {}); | ||
}; | ||
const formalizeRules = banRules => banRules.reduce((rules, rule) => { | ||
const isArrayRule = Array.isArray(rule); | ||
if (isArrayRule) { | ||
return [ | ||
...rules, | ||
...formalizeRules(rule), | ||
]; | ||
} | ||
return [ | ||
...rules, | ||
formalizeRule(rule), | ||
]; | ||
}, []); | ||
//------------------------------------------------------------------------------ | ||
@@ -22,42 +80,25 @@ // Rule Definition | ||
description: 'Ban methods', | ||
category: 'Fill me in', | ||
category: 'Ban', | ||
recommended: false | ||
}, | ||
fixable: null, // or "code" or "whitespace" | ||
schema: [ | ||
{ | ||
'anyOf': [ | ||
{ | ||
'type': 'object', | ||
'properties': { | ||
'name': { | ||
'type': 'string' | ||
}, | ||
'message': { | ||
'type': 'string' | ||
} | ||
}, | ||
'additionalProperties': false, | ||
'required': ['name'], | ||
}, | ||
{ | ||
'type': 'object', | ||
'properties': { | ||
'name': { | ||
'type': 'array', | ||
'items': [ | ||
{ 'type': 'string' }, | ||
{ 'type': 'string' } | ||
] | ||
}, | ||
'message': { | ||
'type': 'string' | ||
} | ||
}, | ||
'additionalProperties': false, | ||
'required': ['name'], | ||
} | ||
] | ||
} | ||
] | ||
schema: { | ||
'anyOf': [ | ||
SIMPLE_BAN_RULE_SCHEMA, | ||
COMPLEX_BAN_RULE_SCHEMA, | ||
{ | ||
'type': 'array', | ||
'minLength': 1, | ||
'uniqueItems': true, | ||
'items': [ | ||
{ | ||
'anyOf': [ | ||
COMPLEX_BAN_RULE_SCHEMA, | ||
SIMPLE_BAN_RULE_SCHEMA, | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
}, | ||
@@ -68,12 +109,5 @@ | ||
const banRules = context.options || []; | ||
const banRulesWidthFunctionDefinitions = banRules.map(rule => { | ||
const isArray = Array.isArray(rule.name); | ||
return isArray | ||
? rule | ||
: Object.assign({ | ||
name: [NO_OBJECT, rule.name], | ||
message: rule.message | ||
}, {}); | ||
}); | ||
const banRulesWidthFunctionDefinitions = formalizeRules(banRules); | ||
//---------------------------------------------------------------------- | ||
@@ -80,0 +114,0 @@ // Helpers |
{ | ||
"name": "eslint-plugin-ban", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Allows you to bannish some methods or functions.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -73,4 +73,22 @@ # eslint-plugin-ban [![Build Status](https://travis-ci.org/remithomas/eslint-plugin-ban.svg?branch=master)](https://travis-ci.org/remithomas/eslint-plugin-ban) [![npm version](https://img.shields.io/npm/v/eslint-plugin-ban.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-ban) | ||
> Multiple errors | ||
```json | ||
{ | ||
"rules": { | ||
"ban/ban": [ | ||
"error", | ||
{"name": "api", "message": "This function is deprecated, please use api.call()"}, | ||
{"name": ["*", "push"], "message": "Prefer use es6 spread like [...items, newItem]"}, | ||
{"name": "functionName", "message": "Prefer use functionName2"} | ||
] | ||
} | ||
} | ||
``` | ||
# Todo | ||
- [ ] Possibility to add `error`and `warning` at same time | ||
# Contributing | ||
Please feel free to submit, comment anything on this repo :) |
@@ -116,1 +116,46 @@ /** | ||
}); | ||
const multipleRuleOptions = [ | ||
{'name': ['animals', 'push'], 'message': 'don\'t push on animals'}, | ||
{'name': ['birds', 'push'], 'message': 'don\'t push on birds'}, | ||
{'name': 'functionName', 'message': 'Prefer use functionName2'} | ||
]; | ||
ruleTester.run('ban with multiple rules', rule, { | ||
valid: [ | ||
{ | ||
code: 'cars.push("dogs");', | ||
options: multipleRuleOptions, | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: 'animals.push("dogs");', | ||
errors: [{ | ||
message: 'don\'t push on animals' | ||
}], | ||
options: multipleRuleOptions | ||
}, | ||
{ | ||
code: 'birds.push("dogs");', | ||
errors: [{ | ||
message: 'don\'t push on birds' | ||
}], | ||
options: multipleRuleOptions | ||
}, | ||
{ | ||
code: 'functionName("dogs");', | ||
errors: [{ | ||
message: 'Prefer use functionName2' | ||
}], | ||
options: multipleRuleOptions | ||
}, | ||
{ | ||
code: 'functionName("dogs");', | ||
errors: [{ | ||
message: 'Prefer use functionName2' | ||
}], | ||
options: multipleRuleOptions | ||
}, | ||
] | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14769
337
94