|
1 | | -import { test } from 'bun:test'; |
| 1 | +import path from 'node:path'; |
| 2 | +import process from 'node:process'; |
| 3 | +import { it } from 'bun:test'; |
2 | 4 | import { RuleTester } from 'eslint'; |
3 | 5 | import correct from '../src/rule'; |
4 | 6 |
|
| 7 | +const cwd = process.cwd(); |
5 | 8 | const tester = new RuleTester(); |
6 | 9 |
|
7 | | -test('rule', () => { |
8 | | - tester.run('rule', correct, { |
9 | | - valid: [{ |
10 | | - filename: '.js', |
11 | | - code: 'f("Hello 世界")', |
12 | | - }, { |
13 | | - filename: '.js', |
14 | | - code: 'f("Hello,世界")\nf("。。。")', |
15 | | - }], |
16 | | - invalid: [{ |
17 | | - filename: '.js', |
18 | | - code: 'console.log("Hello世界")', |
19 | | - errors: 1, |
20 | | - output: 'console.log("Hello 世界")', |
21 | | - }, { |
22 | | - filename: '.js', |
23 | | - code: 'f("Hello ,世界")\nf("啊 ?")', |
24 | | - errors: 2, |
25 | | - output: 'f("Hello,世界")\nf("啊?")', |
26 | | - }], |
27 | | - }); |
28 | | -}); |
| 10 | +it('should work', () => tester.run('rule', correct, { |
| 11 | + valid: [{ |
| 12 | + filename: '.js', |
| 13 | + code: 'f("Hello 世界")', |
| 14 | + }, { |
| 15 | + filename: '.js', |
| 16 | + code: 'f("Hello,世界")\nf("。。。")', |
| 17 | + }], |
| 18 | + |
| 19 | + invalid: [{ |
| 20 | + filename: '.js', |
| 21 | + code: 'console.log("Hello世界")', |
| 22 | + errors: 1, |
| 23 | + output: 'console.log("Hello 世界")', |
| 24 | + }, { |
| 25 | + filename: '.js', |
| 26 | + code: 'f("Hello ,世界")\nf("啊 ?")', |
| 27 | + errors: 2, |
| 28 | + output: 'f("Hello,世界")\nf("啊?")', |
| 29 | + }], |
| 30 | +})); |
| 31 | + |
| 32 | +it('should respect .autocorrectrc', () => tester.run('rule', correct, { |
| 33 | + valid: [{ |
| 34 | + filename: path.join(cwd, 'ignored.js'), |
| 35 | + code: 'f("没有error")', // see .autocorrectrc |
| 36 | + }, { |
| 37 | + filename: path.join(cwd, 'ignored.js'), |
| 38 | + code: 'f("没有 error")', |
| 39 | + }], |
| 40 | + |
| 41 | + invalid: [], |
| 42 | +})); |
| 43 | + |
| 44 | +it('should respect .autocorrectignore', () => tester.run('rule', correct, { |
| 45 | + valid: [{ |
| 46 | + filename: path.resolve(cwd, 'ignored.js'), |
| 47 | + code: 'f("有error")', |
| 48 | + }, { |
| 49 | + filename: path.resolve(cwd, 'ignored.js'), |
| 50 | + code: 'f("有 error")', |
| 51 | + }], |
| 52 | + |
| 53 | + invalid: [], |
| 54 | +})); |
0 commit comments