Skip to content

Commit ac092a7

Browse files
committed
update: check output property is the same as the code property.
1 parent 73978b1 commit ac092a7

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/rules/prefer-output-null.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ module.exports = {
2727
// Public
2828
// ----------------------------------------------------------------------
2929
const message = 'Prefer `output: null` to assert that a test case is not autofixed.';
30-
30+
const sourceCode = context.getSourceCode();
3131
return {
3232
Program (ast) {
3333
utils.getTestInfo(context, ast).forEach(testRun => {
34-
(testRun.invalid || []).forEach(test => {
35-
if (!test.properties.some(item => item.key.name === 'output')) {
36-
context.report({
37-
node: test,
38-
message,
39-
});
40-
}
41-
});
34+
const reportInfo = utils.getReportInfo(testRun.invalid);
35+
const code = sourceCode.getText(reportInfo.code);
36+
const output = sourceCode.getText(reportInfo.output);
37+
if (output && output === code) {
38+
context.report({
39+
node: reportInfo.output,
40+
message,
41+
});
42+
}
4243
});
4344
},
4445
};

tests/lib/rules/prefer-output-null.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ruleTester.run('prefer-output-null', rule, {
4545
new RuleTester().run('foo', bar, {
4646
valid: [],
4747
invalid: [
48-
{code: 'foo', errors: ['bar']},
48+
{code: 'foo', output: 'foo', errors: ['bar']},
4949
]
5050
});
5151
`,

0 commit comments

Comments
 (0)