forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1731780 - Reject .only() chained onto add_task in tests. r=Gijs,m…
…ythmon,Standard8 Differential Revision: https://phabricator.services.mozilla.com/D128027
- Loading branch information
Showing
10 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
docs/code-quality/lint/linters/eslint-plugin-mozilla/reject-addtask-only.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
reject-addtask-only | ||
=================== | ||
|
||
Designed for JavaScript tests using the add_task pattern. Rejects chaining | ||
.only() to an add_task() call, which is useful for local testing to run a | ||
single task in isolation but is easy to land into the tree by accident. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-addtask-only.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @fileoverview Don't allow only() in tests | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Rule Definition | ||
// ----------------------------------------------------------------------------- | ||
|
||
module.exports = function(context) { | ||
// --------------------------------------------------------------------------- | ||
// Public | ||
// -------------------------------------------------------------------------- | ||
|
||
return { | ||
CallExpression(node) { | ||
if ( | ||
node.callee.object && | ||
node.callee.object.callee && | ||
["add_task", "decorate_task"].includes( | ||
node.callee.object.callee.name | ||
) && | ||
node.callee.property && | ||
node.callee.property.name == "only" | ||
) { | ||
context.report({ | ||
node, | ||
message: `add_task(...).only() not allowed - add an exception if this is intentional`, | ||
suggest: [ | ||
{ | ||
desc: "Remove only() call from task", | ||
fix: fixer => | ||
fixer.replaceTextRange( | ||
[node.callee.object.range[1], node.range[1]], | ||
"" | ||
), | ||
}, | ||
], | ||
}); | ||
} | ||
}, | ||
}; | ||
}; |
56 changes: 56 additions & 0 deletions
56
tools/lint/eslint/eslint-plugin-mozilla/tests/reject-addtask-only.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* Any copyright is dedicated to the Public Domain. | ||
* http://creativecommons.org/publicdomain/zero/1.0/ */ | ||
|
||
"use strict"; | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
// ------------------------------------------------------------------------------ | ||
|
||
var rule = require("../lib/rules/reject-addtask-only"); | ||
var RuleTester = require("eslint").RuleTester; | ||
|
||
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 8 } }); | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Tests | ||
// ------------------------------------------------------------------------------ | ||
|
||
function invalidError(output) { | ||
let message = | ||
"add_task(...).only() not allowed - add an exception if this is intentional"; | ||
return [ | ||
{ | ||
message, | ||
type: "CallExpression", | ||
suggestions: [{ desc: "Remove only() call from task", output }], | ||
}, | ||
]; | ||
} | ||
|
||
ruleTester.run("reject-addtask-only", rule, { | ||
valid: [ | ||
"add_task(foo())", | ||
"add_task(foo()).skip()", | ||
"add_task(function() {})", | ||
"add_task(function() {}).skip()", | ||
], | ||
invalid: [ | ||
{ | ||
code: "add_task(foo()).only()", | ||
errors: invalidError("add_task(foo())"), | ||
}, | ||
{ | ||
code: "add_task(foo()).only(bar())", | ||
errors: invalidError("add_task(foo())"), | ||
}, | ||
{ | ||
code: "add_task(function() {}).only()", | ||
errors: invalidError("add_task(function() {})"), | ||
}, | ||
{ | ||
code: "add_task(function() {}).only(bar())", | ||
errors: invalidError("add_task(function() {})"), | ||
}, | ||
], | ||
}); |