|
| 1 | +/** |
| 2 | + * @file The filename should follow the filename naming convention |
| 3 | + * @author Duke Luo |
| 4 | + */ |
| 5 | +'use strict'; |
| 6 | + |
| 7 | +const path = require('path'); |
| 8 | +const proxyquire = require('proxyquire'); |
| 9 | +const RuleTester = require('eslint').RuleTester; |
| 10 | + |
| 11 | +const rule = proxyquire('../../../lib/rules/filename-blacklist', { |
| 12 | + path: { ...path.win32, '@global': true }, |
| 13 | +}); |
| 14 | +const ruleTester = new RuleTester(); |
| 15 | + |
| 16 | +ruleTester.run( |
| 17 | + "filename-blacklist with option on Windows: [{ '*.models.ts': '*.model.ts' }]", |
| 18 | + rule, |
| 19 | + { |
| 20 | + valid: [ |
| 21 | + { |
| 22 | + code: "var foo = 'bar';", |
| 23 | + filename: 'C:\\Users\\Administrator\\Downloads\\wai\\src\\foo.model.ts', |
| 24 | + options: [{ '*.models.ts': '*.model.ts' }], |
| 25 | + }, |
| 26 | + { |
| 27 | + code: "var foo = 'bar';", |
| 28 | + filename: 'src\\foo.model.ts', |
| 29 | + options: [{ '*.models.ts': '*.model.ts' }], |
| 30 | + }, |
| 31 | + ], |
| 32 | + invalid: [ |
| 33 | + { |
| 34 | + code: "var foo = 'bar';", |
| 35 | + filename: |
| 36 | + 'C:\\Users\\Administrator\\Downloads\\wai\\src\\foo.models.ts', |
| 37 | + options: [{ '*.models.ts': '*.model.ts' }], |
| 38 | + errors: [ |
| 39 | + { |
| 40 | + message: |
| 41 | + 'The filename "foo.models.ts" matches the blacklisted "*.models.ts" pattern. Use a pattern like "*.model.ts" instead.', |
| 42 | + column: 1, |
| 43 | + line: 1, |
| 44 | + }, |
| 45 | + ], |
| 46 | + }, |
| 47 | + { |
| 48 | + code: "var foo = 'bar';", |
| 49 | + filename: 'src\\foo.models.ts', |
| 50 | + options: [{ '*.models.ts': '*.model.ts' }], |
| 51 | + errors: [ |
| 52 | + { |
| 53 | + message: |
| 54 | + 'The filename "foo.models.ts" matches the blacklisted "*.models.ts" pattern. Use a pattern like "*.model.ts" instead.', |
| 55 | + column: 1, |
| 56 | + line: 1, |
| 57 | + }, |
| 58 | + ], |
| 59 | + }, |
| 60 | + ], |
| 61 | + } |
| 62 | +); |
| 63 | + |
| 64 | +ruleTester.run( |
| 65 | + "filename-blacklist with option on Windows: [{ '*.models.ts': 'FOO' }]", |
| 66 | + rule, |
| 67 | + { |
| 68 | + valid: [], |
| 69 | + |
| 70 | + invalid: [ |
| 71 | + { |
| 72 | + code: "var foo = 'bar';", |
| 73 | + filename: 'src\\foo.models.ts', |
| 74 | + options: [{ '*.models.ts': 'FOO' }], |
| 75 | + errors: [ |
| 76 | + { |
| 77 | + message: 'There is an invalid pattern "FOO", please check it', |
| 78 | + column: 1, |
| 79 | + line: 1, |
| 80 | + }, |
| 81 | + ], |
| 82 | + }, |
| 83 | + ], |
| 84 | + } |
| 85 | +); |
| 86 | + |
| 87 | +ruleTester.run( |
| 88 | + "filename-blacklist with option on Windows: [{ 'models.ts': '*.model.ts' }]", |
| 89 | + rule, |
| 90 | + { |
| 91 | + valid: [], |
| 92 | + |
| 93 | + invalid: [ |
| 94 | + { |
| 95 | + code: "var foo = 'bar';", |
| 96 | + filename: 'src\\foo.models.ts', |
| 97 | + options: [{ 'models.ts': '*.model.ts' }], |
| 98 | + errors: [ |
| 99 | + { |
| 100 | + message: 'There is an invalid pattern "models.ts", please check it', |
| 101 | + column: 1, |
| 102 | + line: 1, |
| 103 | + }, |
| 104 | + ], |
| 105 | + }, |
| 106 | + ], |
| 107 | + } |
| 108 | +); |
0 commit comments