|
1 | 1 | /** |
2 | 2 | * @author kazuya kawaguchi (a.k.a. kazupon) |
3 | 3 | */ |
4 | | -import { CLIEngine, RuleTester } from 'eslint' |
5 | | -import { resolve, join } from 'path' |
| 4 | +import { RuleTester } from 'eslint' |
| 5 | +import { join } from 'path' |
6 | 6 | import fs from 'fs' |
7 | | -import assert from 'assert' |
8 | 7 | import rule = require('../../../lib/rules/no-html-messages') |
9 | | -import plugin = require('../../../lib/index') |
10 | | -import { baseConfigPath } from '../test-utils' |
| 8 | +import { testOnFixtures } from '../test-utils' |
11 | 9 |
|
12 | 10 | new RuleTester({ |
13 | 11 | parser: require.resolve('vue-eslint-parser'), |
@@ -101,84 +99,64 @@ new RuleTester({ |
101 | 99 | }) |
102 | 100 |
|
103 | 101 | describe('no-html-messages with fixtures', () => { |
104 | | - const cwd = join(__dirname, '../../fixtures/no-html-messages') |
105 | | - let originalCwd: string |
106 | | - |
107 | | - before(() => { |
108 | | - originalCwd = process.cwd() |
109 | | - process.chdir(cwd) |
110 | | - }) |
111 | | - |
112 | | - after(() => { |
113 | | - process.chdir(originalCwd) |
114 | | - }) |
| 102 | + const cwdRoot = join(__dirname, '../../fixtures/no-html-messages') |
115 | 103 |
|
116 | 104 | describe('valid', () => { |
117 | 105 | it('should be not detected html messages', () => { |
118 | | - const linter = new CLIEngine({ |
119 | | - cwd, |
120 | | - baseConfig: { |
121 | | - extends: [baseConfigPath], |
122 | | - settings: { |
123 | | - 'vue-i18n': { |
124 | | - localeDir: `./valid/*.{json,yaml,yml}` |
125 | | - } |
126 | | - } |
127 | | - }, |
128 | | - useEslintrc: false, |
129 | | - parserOptions: { |
130 | | - ecmaVersion: 2015 |
131 | | - }, |
132 | | - rules: { |
133 | | - '@intlify/vue-i18n/no-html-messages': 'error' |
| 106 | + testOnFixtures( |
| 107 | + { |
| 108 | + cwd: join(cwdRoot, './valid'), |
| 109 | + localeDir: `*.{json,yaml,yml}`, |
| 110 | + ruleName: '@intlify/vue-i18n/no-html-messages' |
134 | 111 | }, |
135 | | - extensions: ['.js', '.vue', '.json', '.yaml', '.yml'] |
136 | | - }) |
137 | | - |
138 | | - linter.addPlugin('@intlify/vue-i18n', plugin) |
139 | | - const messages = linter.executeOnFiles(['.']) |
140 | | - assert.equal(messages.errorCount, 0) |
| 112 | + {} |
| 113 | + ) |
141 | 114 | }) |
142 | 115 | }) |
143 | 116 |
|
144 | 117 | describe('invalid', () => { |
145 | 118 | it('should be detected html messages', () => { |
146 | | - const linter = new CLIEngine({ |
147 | | - cwd, |
148 | | - baseConfig: { |
149 | | - extends: [baseConfigPath], |
150 | | - settings: { |
151 | | - 'vue-i18n': { |
152 | | - localeDir: `./invalid/*.{json,yaml,yml}` |
153 | | - } |
154 | | - } |
155 | | - }, |
156 | | - useEslintrc: false, |
157 | | - parserOptions: { |
158 | | - ecmaVersion: 2015 |
159 | | - }, |
160 | | - rules: { |
161 | | - '@intlify/vue-i18n/no-html-messages': 'error' |
| 119 | + testOnFixtures( |
| 120 | + { |
| 121 | + cwd: join(cwdRoot, './invalid'), |
| 122 | + localeDir: `*.{json,yaml,yml}`, |
| 123 | + ruleName: '@intlify/vue-i18n/no-html-messages' |
162 | 124 | }, |
163 | | - extensions: ['.js', '.vue', '.json', '.yaml', '.yml'] |
164 | | - }) |
165 | | - linter.addPlugin('@intlify/vue-i18n', plugin) |
166 | | - |
167 | | - const messages = linter.executeOnFiles(['.']) |
168 | | - assert.equal(messages.errorCount, 6) |
169 | | - |
170 | | - function checkRuleId(path: string) { |
171 | | - const fullPath = resolve(__dirname, path) |
172 | | - const result = messages.results.find( |
173 | | - result => result.filePath === fullPath |
174 | | - )! |
175 | | - assert.equal(result.messages.length, 3) |
176 | | - result.messages.forEach(message => { |
177 | | - assert.equal(message.ruleId, '@intlify/vue-i18n/no-html-messages') |
178 | | - }) |
179 | | - } |
180 | | - checkRuleId('../../fixtures/no-html-messages/invalid/en.json') |
181 | | - checkRuleId('../../fixtures/no-html-messages/invalid/en.yaml') |
| 125 | + { |
| 126 | + 'en.json': { |
| 127 | + errors: [ |
| 128 | + { |
| 129 | + line: 3, |
| 130 | + message: 'used HTML localization message' |
| 131 | + }, |
| 132 | + { |
| 133 | + line: 5, |
| 134 | + message: 'used HTML localization message' |
| 135 | + }, |
| 136 | + { |
| 137 | + line: 6, |
| 138 | + message: 'used HTML localization message' |
| 139 | + } |
| 140 | + ] |
| 141 | + }, |
| 142 | + 'en.yaml': { |
| 143 | + errors: [ |
| 144 | + { |
| 145 | + line: 2, |
| 146 | + message: 'used HTML localization message' |
| 147 | + }, |
| 148 | + { |
| 149 | + line: 4, |
| 150 | + message: 'used HTML localization message' |
| 151 | + }, |
| 152 | + { |
| 153 | + line: 5, |
| 154 | + message: 'used HTML localization message' |
| 155 | + } |
| 156 | + ] |
| 157 | + } |
| 158 | + } |
| 159 | + ) |
182 | 160 | }) |
183 | 161 | }) |
184 | 162 | }) |
0 commit comments