-
Notifications
You must be signed in to change notification settings - Fork 0
/
text-decoder.ts
35 lines (32 loc) · 1.24 KB
/
text-decoder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { AST_NODE_TYPES } from '@typescript-eslint/types';
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../../../../src/rules/prefer-global/text-decoder';
const error = (global?: boolean): TSESLint.TestCaseError<`prefer${'Global' | 'Module'}`> => ({
messageId: `prefer${global ? 'Global' : 'Module'}`,
line: 1,
column: global ? 7 : 13,
data: {},
type: global ? AST_NODE_TYPES.Property : AST_NODE_TYPES.Identifier,
});
new TSESLint.RuleTester({
parserOptions: { ecmaVersion: 2015 },
globals: { TextDecoder: 'readonly', require: 'readonly' },
} as unknown as TSESLint.RuleTesterConfig).run('prefer-global/text-decoder', rule, {
valid: [
'var b = new TextDecoder(s)',
{ code: 'var b = new TextDecoder(s)', options: ['always'] },
{ code: "var { TextDecoder } = require('util'); var b = new TextDecoder(s)", options: ['never'] },
],
invalid: [
{
code: "var { TextDecoder } = require('util'); var b = new TextDecoder(s)",
errors: [error(true)],
},
{
code: "var { TextDecoder } = require('util'); var b = new TextDecoder(s)",
options: ['always'],
errors: [error(true)],
},
{ code: 'var b = new TextDecoder(s)', options: ['never'], errors: [error()] },
],
});