Skip to content

Commit

Permalink
deduplicate and document new rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Aug 7, 2017
1 parent 9aa0ece commit 8b8fa79
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 61 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,8 @@ Inspired by [this talk](https://www.youtube.com/watch?v=PSGEjv3Tqo0).

| Name | Description | Default Configuration |
| ------------- | ------------- | ------------- |
| no-classes | Forbids use of classes. | 'no-classes': 0 |
| no-deletes | Forbids use of delete. | 'no-deletes': 2 |
| no-exceptions | Forbids throwing and catching errors. | 'no-exceptions': 2 |
| no-exports | Forbids use of export keyword. | 'no-exports': 0 |
| no-fors | Forbids use for, for-in, for of statements. | 'no-fors': 2 |
| no-function-expressions | Forbids use function expressions. | 'no-function-expressions': 0 |
| no-ifs | Forbids use of if statements. | 'no-ifs': 2 |
| no-imports | Forbids use of import keyword. | 'no-imports': 0 |
Expand All @@ -124,10 +121,9 @@ Inspired by [this talk](https://www.youtube.com/watch?v=PSGEjv3Tqo0).
| no-reassigns | Forbids reassigning variables. | 'no-reassigns': 2 |
| no-switches | Forbids use of switch statement. | 'no-switches': 2 |
| no-this | Forbids use of this. | 'no-this': 2 |
| no-typeof | Forbids typeof operator. | 'no-typeofs': 2 |
| no-typeofs | Forbids typeof operator. | 'no-typeofs': 2 |
| no-undefined | Forbids use of undefined. | 'no-undefined': 0 |
| no-variable-declaration | Forbids declaring variables. | 'no-variable-declaration': 0 |
| no-whiles | Forbids use while, do-while statements. | 'no-whiles': 2 |
| must-return | Every branch of every function should have a return statement. | 'must-return': 2 |
| explicit-return | Stricter version of must-return: every function should have a top level return statement. | 'explicit-return': 2 |

Expand Down
13 changes: 12 additions & 1 deletion rules/explicit-return.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (context) {
const create = function (context) {
const functions = [];
function enterFunction(node) {
return functions.push(node);
Expand Down Expand Up @@ -27,3 +27,14 @@ module.exports = function (context) {
}
};
};

module.exports = {
create,
meta: {
docs: {
description:
'Stricter version of must-return: every function should have a top level return statement.',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/must-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function isSimpleArrow(node) {
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function (context) {
const create = function (context) {
const treatUndefinedAsUnspecified = false;
let funcInfo = null;

Expand Down Expand Up @@ -187,3 +187,13 @@ module.exports = function (context) {
'ArrowFunctionExpression:exit': checkLastSegment
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Every branch of every function should have a return statement.',
recommended: 'off'
}
}
};
7 changes: 0 additions & 7 deletions rules/no-classes.js

This file was deleted.

9 changes: 0 additions & 9 deletions rules/no-deletes.js

This file was deleted.

12 changes: 11 additions & 1 deletion rules/no-exceptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (context) {
const create = function (context) {
return [
'ThrowStatement',
'TryStatement',
Expand All @@ -10,3 +10,13 @@ module.exports = function (context) {
return acc;
}, {});
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids throwing and catching errors.',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/no-exports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (context) {
const create = function (context) {
return [
'ExportNamedDeclaration',
'ExportDefaultDeclaration',
Expand All @@ -10,3 +10,13 @@ module.exports = function (context) {
return acc;
}, {});
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids use of export keyword',
recommended: 'off'
}
}
};
12 changes: 0 additions & 12 deletions rules/no-fors.js

This file was deleted.

12 changes: 11 additions & 1 deletion rules/no-function-expressions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
module.exports = function (context) {
const create = function (context) {
return {
FunctionExpression(node) {
return context.report(node, 'Unexpected function expression, use fat arrow expression instead');
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids the use of function expressions, consider: prefer-arrow-callback',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/no-ifs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
module.exports = function (context) {
const create = function (context) {
return {
IfStatement(node) {
return context.report(node, 'Unexpected if statement, use ternary expression instead');
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids the use of `if` statements, in favour of ternary expressions',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/no-imports.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
module.exports = function (context) {
const create = function (context) {
return {
ImportDeclaration(node) {
return context.report(node, 'Unexpected import statement, use CJS require function instead');
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids the use of the `import` keyword, in favour of CommonJS',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/no-instanceofs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (context) {
const create = function (context) {
return {
UnaryExpression(node) {
return node.operator === 'instanceof' ?
Expand All @@ -7,3 +7,13 @@ module.exports = function (context) {
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids the use of the `instanceof` operator',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/no-new.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
module.exports = function (context) {
const create = function (context) {
return {
NewExpression(node) {
context.report(node, 'Unexpected "new" expression');
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids the use of the `new` keyword',
recommended: 'off'
}
}
};
14 changes: 12 additions & 2 deletions rules/no-nulls.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
module.exports = function (context) {
const create = function (context) {
return {
Null(node) {
return context.report(node, 'Unexpected null, use undefined instead');
return context.report(node, 'Unexpected null, use an Option/Maybe Monad instead');
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids the use of `null`.',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/no-reassigns.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (context) {
const create = function (context) {
return {
AssignmentExpression(node) {
return node.left && node.left.type === 'MemberExpression' && node.left.property && node.left.property.name === 'exports' ?
Expand All @@ -7,3 +7,13 @@ module.exports = function (context) {
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids reassigning variables',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/no-switches.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
module.exports = function (context) {
const create = function (context) {
return {
SwitchStatement(node) {
return context.report(node, 'Unexpected switch statement, use pattern matching library instead');
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids the use of the `switch` statement',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/no-typeofs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (context) {
const create = function (context) {
return {
UnaryExpression(node) {
return node.operator === 'typeof' ?
Expand All @@ -7,3 +7,13 @@ module.exports = function (context) {
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids the typeof operator',
recommended: 'off'
}
}
};
14 changes: 12 additions & 2 deletions rules/no-undefined.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
module.exports = function (context) {
const create = function (context) {
return {
Identifier(node) {
return node.value === 'undefined' ?
context.report(node, 'Unexpected undefined, use null instead') :
context.report(node, 'Unexpected undefined, use an Option/Maybe Monad instead') :
undefined;
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids the use of `undefined`.',
recommended: 'off'
}
}
};
12 changes: 11 additions & 1 deletion rules/no-variable-declarations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (context) {
const create = function (context) {
return {
VariableDeclaration(node) {
return ['var', 'let'].indexOf(node.kind) === -1 ?
Expand All @@ -7,3 +7,13 @@ module.exports = function (context) {
}
};
};

module.exports = {
create,
meta: {
docs: {
description: 'Forbids variable declarations, no `var` or `let`.',
recommended: 'off'
}
}
};
11 changes: 0 additions & 11 deletions rules/no-whiles.js

This file was deleted.

0 comments on commit 8b8fa79

Please sign in to comment.