Skip to content

Commit 0547c7e

Browse files
committed
[Tests] add test case for #1645
1 parent e1ed323 commit 0547c7e

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ coverage
44
node_modules
55
tests/files/malformed.js
66
tests/files/with-syntax-error
7+
tests/files/just-json-files/invalid.json
78
resolvers/webpack/test/files
89
# we want to ignore "tests/files" here, but unfortunately doing so would
910
# interfere with unit test and fail it for some reason.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"eslint-module-utils": "file:./utils",
7878
"eslint-plugin-eslint-plugin": "^2.2.1",
7979
"eslint-plugin-import": "2.x",
80+
"eslint-plugin-json": "^2.1.1",
8081
"fs-copy-file-sync": "^1.1.1",
8182
"glob": "^7.1.6",
8283
"in-publish": "^2.0.0",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"root": true,
3+
4+
"plugins": ["import", "json"],
5+
6+
"rules": {
7+
"import/no-unused-modules": [
8+
"error",
9+
{
10+
"missingExports": false,
11+
"unusedExports": true
12+
}
13+
]
14+
},
15+
16+
"overrides": [
17+
{
18+
"files": "*.json",
19+
"extends": "plugin:json/recommended"
20+
}
21+
]
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
,

tests/src/cli.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/**
22
* tests that require fully booting up ESLint
33
*/
4+
import path from 'path'
5+
46
import { expect } from 'chai'
57
import { CLIEngine } from 'eslint'
8+
import eslintPkg from 'eslint/package.json'
9+
import semver from 'semver'
610

711
describe('CLI regression tests', function () {
812
describe('issue #210', function () {
@@ -21,4 +25,55 @@ describe('CLI regression tests', function () {
2125
expect(() => cli.executeOnFiles(['./tests/files/issue210.js'])).not.to.throw(Error)
2226
})
2327
})
28+
29+
describe('issue #1645', function () {
30+
let cli
31+
beforeEach(function () {
32+
if (semver.satisfies(eslintPkg.version, '< 6')) {
33+
this.skip()
34+
} else {
35+
cli = new CLIEngine({
36+
useEslintrc: false,
37+
configFile: './tests/files/just-json-files/.eslintrc.json',
38+
rulePaths: ['./src/rules'],
39+
ignore: false,
40+
})
41+
}
42+
})
43+
44+
it('throws an error on invalid JSON', function () {
45+
const invalidJSON = './tests/files/just-json-files/invalid.json'
46+
const results = cli.executeOnFiles([invalidJSON])
47+
expect(results).to.eql({
48+
results: [
49+
{
50+
filePath: path.resolve(invalidJSON),
51+
messages: [
52+
{
53+
column: 2,
54+
endColumn: 3,
55+
endLine: 1,
56+
line: 1,
57+
message: 'Expected a JSON object, array or literal.',
58+
nodeType: results.results[0].messages[0].nodeType, // we don't care about this one
59+
ruleId: 'json/*',
60+
severity: 2,
61+
source: '\n',
62+
},
63+
],
64+
errorCount: 1,
65+
warningCount: 0,
66+
fixableErrorCount: 0,
67+
fixableWarningCount: 0,
68+
source: ',\n',
69+
},
70+
],
71+
errorCount: 1,
72+
warningCount: 0,
73+
fixableErrorCount: 0,
74+
fixableWarningCount: 0,
75+
usedDeprecatedRules: results.usedDeprecatedRules, // we don't care about this one
76+
})
77+
})
78+
})
2479
})

0 commit comments

Comments
 (0)