Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/tests/src/rules/no-amd.js
829 views
1
import { RuleTester } from 'eslint';
2
import eslintPkg from 'eslint/package.json';
3
import semver from 'semver';
4
5
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015, sourceType: 'module' } });
6
7
ruleTester.run('no-amd', require('rules/no-amd'), {
8
valid: [
9
{ code: 'import "x";', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } },
10
{ code: 'import x from "x"', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } },
11
'var x = require("x")',
12
13
'require("x")',
14
// 2-args, not an array
15
'require("x", "y")',
16
// random other function
17
'setTimeout(foo, 100)',
18
// non-identifier callee
19
'(a || b)(1, 2, 3)',
20
21
// nested scope is fine
22
'function x() { define(["a"], function (a) {}) }',
23
'function x() { require(["a"], function (a) {}) }',
24
25
// unmatched arg types/number
26
'define(0, 1, 2)',
27
'define("a")',
28
],
29
30
invalid: semver.satisfies(eslintPkg.version, '< 4.0.0') ? [] : [
31
{ code: 'define([], function() {})', errors: [ { message: 'Expected imports instead of AMD define().' }] },
32
{ code: 'define(["a"], function(a) { console.log(a); })', errors: [ { message: 'Expected imports instead of AMD define().' }] },
33
34
{ code: 'require([], function() {})', errors: [ { message: 'Expected imports instead of AMD require().' }] },
35
{ code: 'require(["a"], function(a) { console.log(a); })', errors: [ { message: 'Expected imports instead of AMD require().' }] },
36
],
37
});
38
39