Skip to content

Commit 0694945

Browse files
committed
dropping support for prettier v2
1 parent 7208bf1 commit 0694945

20 files changed

+44
-205
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,6 @@ jobs:
4141
- name: Run tests
4242
run: npm run test:standalone
4343

44-
test_prettier_v2:
45-
name: Prettier V2
46-
runs-on: ubuntu-latest
47-
steps:
48-
- uses: actions/checkout@v3
49-
- uses: actions/setup-node@v3
50-
with:
51-
node-version: 16
52-
cache: 'npm'
53-
- name: Install
54-
run: npm install
55-
- name: Build with Prettier V3
56-
run: npm run build
57-
- name: Downgrade Prettier to V2
58-
run: npm install [email protected]
59-
- name: Build test app
60-
run: npm run build:test
61-
- name: Run standalone tests
62-
run: npm run test:standalone
63-
6444
test_linux:
6545
name: Test on Linux with Node ${{ matrix.node }}
6646
runs-on: ubuntu-latest

package-lock.json

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"lint:fix": "npm run eslint -- --fix && npm run prettier -- --write",
2020
"prepublishOnly": "npm run build && npx tsc",
2121
"prettier": "prettier './*.{ts,js,cjs,json,md,yml}' '{src,tests}/**/*.{ts,js,cjs}'",
22-
"test": "NODE_OPTIONS=\"--loader=ts-node/esm --loader=esmock\" jest",
23-
"test:all": "cross-env FULL_TEST=1 NODE_OPTIONS=\"--loader=ts-node/esm --loader=esmock\" c8 jest",
24-
"test:standalone": "cross-env TEST_STANDALONE=1 FULL_TEST=1 NODE_OPTIONS=\"--loader=esmock\" jest"
22+
"test": "NODE_OPTIONS=\"--loader=ts-node/esm\" jest",
23+
"test:all": "cross-env FULL_TEST=1 NODE_OPTIONS=\"--loader=ts-node/esm\" c8 jest",
24+
"test:standalone": "cross-env TEST_STANDALONE=1 FULL_TEST=1 jest"
2525
},
2626
"files": [
2727
"src",
@@ -94,7 +94,6 @@
9494
"eslint": "^9.13.0",
9595
"eslint-config-prettier": "^9.1.0",
9696
"esm-utils": "^4.3.0",
97-
"esmock": "^2.6.9",
9897
"jest": "^29.7.0",
9998
"jest-light-runner": "^0.6.0",
10099
"jest-snapshot-serializer-ansi": "^2.1.0",
@@ -116,7 +115,7 @@
116115
"semver": "^7.6.3"
117116
},
118117
"peerDependencies": {
119-
"prettier": ">=2.3.0"
118+
"prettier": ">=3.0.0"
120119
},
121120
"browserslist": {
122121
"production": [

src/printer.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,8 @@ const warnDeprecation = once(() => {
2323
return true;
2424
});
2525

26-
const prettierVersionCheck = once(() => {
27-
if (!prettierVersionSatisfies('>=2.3.0')) {
28-
throw new Error(
29-
'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
30-
);
31-
}
32-
return true;
33-
});
34-
3526
function genericPrint(path, options, print) {
3627
warnDeprecation();
37-
prettierVersionCheck();
3828

3929
const node = path.getValue();
4030
if (node === null) {

src/slang-comments/handlers/handle-contract-definition-comments.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
3-
import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js';
3+
import { locEnd } from '../../slang-utils/loc.js';
44
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
55

66
import type { HandlerParams } from './types.d.ts';
@@ -18,7 +18,10 @@ export default function handleContractDefinitionComments({
1818
return false;
1919
}
2020

21-
const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment);
21+
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
22+
text,
23+
locEnd(comment)
24+
);
2225

2326
// Everything before the InheritanceSpecifier is pushed onto the beginning of
2427
// the ContractDefinition.

src/slang-comments/handlers/handle-if-statement-comments.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
3-
import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js';
3+
import { locEnd } from '../../slang-utils/loc.js';
44
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
55

66
import type { HandlerParams } from './types.d.ts';
@@ -23,7 +23,10 @@ export default function handleIfStatementComments({
2323
// if (a /* comment */) {}
2424
// The only workaround I found is to look at the next character to see if
2525
// it is a ).
26-
const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment);
26+
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
27+
text,
28+
locEnd(comment)
29+
);
2730
if (nextCharacter === ')') {
2831
addTrailingComment(precedingNode, comment);
2932
return true;

src/slang-comments/handlers/handle-interface-definition-comments.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
2-
import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js';
2+
import { util } from 'prettier';
3+
import { locEnd } from '../../slang-utils/loc.js';
34
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
45
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
56

@@ -16,7 +17,10 @@ export default function handleInterfaceDefinitionComments({
1617
return false;
1718
}
1819

19-
const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment);
20+
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
21+
text,
22+
locEnd(comment)
23+
);
2024

2125
// The comment is at the end of the body of the InterfaceDefinition.
2226
if (precedingNode?.kind === NonterminalKind.InterfaceMembers) {

src/slang-comments/handlers/handle-library-definition-comments.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
2-
import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js';
2+
import { util } from 'prettier';
3+
import { locEnd } from '../../slang-utils/loc.js';
34
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
45
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
56

@@ -16,7 +17,10 @@ export default function handleLibraryDefinitionComments({
1617
return false;
1718
}
1819

19-
const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment);
20+
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
21+
text,
22+
locEnd(comment)
23+
);
2024

2125
// The comment is at the end of the body of the ContractDefinition.
2226
if (precedingNode?.kind === NonterminalKind.LibraryMembers) {

src/slang-comments/handlers/handle-modifier-invocation-comments.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
3-
import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js';
3+
import { locEnd } from '../../slang-utils/loc.js';
44
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
55

66
import type { HandlerParams } from './types.d.ts';
@@ -18,7 +18,10 @@ export default function handleModifierInvocationComments({
1818
return false;
1919
}
2020

21-
const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment);
21+
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
22+
text,
23+
locEnd(comment)
24+
);
2225

2326
// The last comments before the body.
2427
if (

src/slang-comments/handlers/handle-while-statement-comments.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
3-
import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js';
3+
import { locEnd } from '../../slang-utils/loc.js';
44
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
55

66
import type { HandlerParams } from './types.d.ts';
@@ -26,7 +26,10 @@ export default function handleWhileStatementComments({
2626
// while (a /* comment */) {}
2727
// The only workaround I found is to look at the next character to see if
2828
// it is a ).
29-
const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment);
29+
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
30+
text,
31+
locEnd(comment)
32+
);
3033
if (nextCharacter === ')' || enclosingNode.condition === precedingNode) {
3134
addTrailingComment(precedingNode, comment);
3235
return true;

0 commit comments

Comments
 (0)