- Start Date: 2019-07-16
- RFC PR: (leave this empty, to be filled in later)
- Authors: Toru Nagashima (@mysticatea)
This RFC makes RuleTester
class supporting processor
option.
Currently, we cannot test rules with processors. This is inconvenient for plugin rules which depend on processors. For example, vue/comment-directive rule could not use RuleTester
to test.
To add processor
option and processorOptions
(see #29) to test cases.
const { RuleTester } = require("eslint")
const rule = require("../../../lib/rules/example-rule")
const exampleProcessor = require("../../../lib/processors/example-processor")
const tester = new RuleTester()
tester.run("example-rule", rule, {
valid: [
{
code: `
<script>
console.log("Hello")
</script>
`,
processor: exampleProcessor,
processorOptions: {},
},
],
invalid: [],
})
This is a definition object of a processor that the "Processors in Plugins" section describes.
If this option was given, the tester applies the given processor to test code.
If the given processor didn't has supportsAutofix:true
, the tester doesn't do autofix. Then if the test case had output
option (except null
) then the test case will fail.
RFC #29 defines the processorOptions
.
If this option was given along with processor
option, it will be given to the processor.
The RuleTester section should describe the new processor
and processorOptions
properties.
It's a pretty rare case of a rule depends on the processor's behavior. I'm not sure if this feature is needed.
There are no concerns about breaking changes.