Skip to content

Commit e5e7e52

Browse files
authored
Throwing if the prettier version is not >=2.3.0 (#552)
* Throwing if the prettier version is not >=2.3.0 * grammar
1 parent e02a5af commit e5e7e52

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/printer.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1+
const prettier = require('prettier');
2+
const semver = require('semver');
13
const nodes = require('./nodes');
24
const { hasNodeIgnoreComment } = require('./prettier-comments/common/util');
35
const ignoreComments = require('./comments/ignore');
46

7+
let checked = false;
8+
9+
function prettierVersionCheck() {
10+
if (checked) return;
11+
if (!semver.satisfies(prettier.version, '>=2.3.0')) {
12+
throw new Error(
13+
'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
14+
);
15+
}
16+
checked = true;
17+
}
18+
519
function genericPrint(path, options, print) {
20+
prettierVersionCheck();
21+
622
const node = path.getValue();
723
if (node === null) {
824
return '';

tests/config/format-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function runSpec(fixtures, parsers, options) {
195195

196196
describe(title, () => {
197197
const formatOptions = {
198-
plugins: [path.dirname(path.join(__dirname, ".."))],
198+
plugins: [path.join(__dirname, "../..")],
199199
printWidth: 80,
200200
...options,
201201
filepath: filename,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const path = require('path');
2+
3+
jest.mock('prettier', () => {
4+
// Require the original module to not be mocked...
5+
const originalModule = jest.requireActual('prettier');
6+
7+
return {
8+
...originalModule,
9+
version: '2.2.1'
10+
};
11+
});
12+
13+
const prettier = require('prettier');
14+
15+
test('should throw if the installed version of prettier is less than v2.3.0', () => {
16+
const data = 'contract CheckPrettierVersion {}';
17+
18+
const options = {
19+
plugins: [path.join(__dirname, '../..')],
20+
parser: 'solidity-parse'
21+
};
22+
23+
expect(() => {
24+
prettier.format(data, options);
25+
}).toThrow('>=2.3.0');
26+
});

0 commit comments

Comments
 (0)