Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit last line if there's a parent parser #765

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
coverage/**/*.js
tests/format/**/*.sol
tests/format/Markdown/Markdown.md
tests/format/RespectDefaultOptions/respect-default-options.js
tests/config/**/*.js
src/prettier-comments/**/*.js
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coverage/**/*.js
tests/format/**/*.sol
tests/format/Markdown/Markdown.md
tests/format/RespectDefaultOptions/respect-default-options.js
src/prettier-comments/**/*.js
2 changes: 1 addition & 1 deletion src/nodes/SourceUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const printPreservingEmptyLines = require('./print-preserving-empty-lines');
const SourceUnit = {
print: ({ options, path, print }) => [
printPreservingEmptyLines(path, 'children', options, print),
line
options.parentParser ? '' : line
]
};

Expand Down
15 changes: 13 additions & 2 deletions tests/config/require-standalone.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
"use strict";

const prettier = require("prettier/standalone");
const markdownPlugin = require("prettier/parser-markdown");
const babelPlugin = require("prettier/parser-babel");
const solidityPlugin = require("../../src/index");

module.exports = {
formatWithCursor(input, options) {
const $$$options = {
...options,
plugins: [babelPlugin, solidityPlugin, ...(options.plugins || [])],
plugins: [
babelPlugin,
markdownPlugin,
solidityPlugin,
...(options.plugins || []),
],
};
return prettier.formatWithCursor(input, $$$options);
},
Expand All @@ -17,7 +23,12 @@ module.exports = {
parse(input, options, massage) {
const $$$options = {
...options,
plugins: [babelPlugin, solidityPlugin, ...(options.plugins || [])],
plugins: [
babelPlugin,
markdownPlugin,
solidityPlugin,
...(options.plugins || []),
],
};
return prettier.__debug.parse(input, $$$options, massage);
},
Expand Down
13 changes: 13 additions & 0 deletions tests/format/Markdown/Markdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Embedded Solidity Code

- original

<!-- prettier-ignore -->
```solidity
import "./Foo.sol";
```

- formatted
```solidity
import "./Foo.sol";
```
40 changes: 40 additions & 0 deletions tests/format/Markdown/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Markdown.md format 1`] = `
====================================options=====================================
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# Embedded Solidity Code

- original

<!-- prettier-ignore -->
\`\`\`solidity
import "./Foo.sol";
\`\`\`

- formatted
\`\`\`solidity
import "./Foo.sol";
\`\`\`

=====================================output=====================================
# Embedded Solidity Code

- original

<!-- prettier-ignore -->
\`\`\`solidity
import "./Foo.sol";
\`\`\`

- formatted

\`\`\`solidity
import "./Foo.sol";
\`\`\`

================================================================================
`;
1 change: 1 addition & 0 deletions tests/format/Markdown/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, ['markdown']);