How to use the RuleTester function from eslint

Find comprehensive JavaScript eslint.RuleTester code examples handpicked from public code repositorys.

1
2
3
4
5
6
7
8
9
10

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 74';
jest.resetModules();

const ruleTester = new RuleTester({
  parserOptions: {
    ecmaVersion: 2021,
  },
  globals: {
fork icon9
star icon43
watch icon2

21
22
23
24
25
26
27
28
29
30
constructor(options) {
    super(options);

    this._liferay = {
        parsers: {
            'babel-eslint': new RuleTester({
                ...options,
                parser: require.resolve('babel-eslint'),
            }),
            'espree': new RuleTester(options),
fork icon62
star icon0
watch icon1

+ 5 other calls in file

13
14
15
16
17
18
19
20
21
22
  })),
}))

const filename = '@looker/components/src/index.js'

new RuleTester({
  parser: require.resolve('jsonc-eslint-parser'),
}).run('publish-config', rule, {
  valid: [
    {
fork icon28
star icon51
watch icon22

220
221
222
223
224
225
226
227
228
Para iniciarmos, vamos criar um arquivo e criar uma instância desse `RuleTester`:

```js
// arquivo teste.js
const { RuleTester } = require('eslint');
const tester = new RuleTester();
```

Caso seja necessário, você pode passar configurações extras ao instanciar o `RuleTester` para realizar qualquer configuração extra do ESLint.
fork icon1
star icon0
watch icon1

+ 3 other calls in file