Skip to content

Commit

Permalink
adding support for prettier-ignore (prettier-solidity#202)
Browse files Browse the repository at this point in the history
* adding support for prettier-ignore

* the test look nicer now
  • Loading branch information
Janther authored and mattiaerre committed Sep 20, 2019
1 parent cb326d5 commit d20a205
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/printer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const nodes = require('./nodes');
const { hasNodeIgnoreComment } = require('./prettier-comments/common/util.js');

function genericPrint(path, options, print) {
const node = path.getValue();
Expand All @@ -10,6 +11,10 @@ function genericPrint(path, options, print) {
throw new Error(`Unknown type: ${JSON.stringify(node.type)}`);
}

if (hasNodeIgnoreComment(node)) {
return options.originalText.slice(node.range[0], node.range[1] + 1);
}

return nodes[node.type].print({ node, options, path, print });
}

Expand Down
18 changes: 18 additions & 0 deletions tests/PrettierIgnore/PrettierIgnore.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity ^0.5.2;

contract PrettierIgnore {
function() public payable {
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
);

// prettier-ignore
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
);
}
}
38 changes: 38 additions & 0 deletions tests/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PrettierIgnore.sol 1`] = `
pragma solidity ^0.5.2;
contract PrettierIgnore {
function() public payable {
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
);
// prettier-ignore
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pragma solidity ^0.5.2;
contract PrettierIgnore {
function() public payable {
matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
// prettier-ignore
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
);
}
}
`;
1 change: 1 addition & 0 deletions tests/PrettierIgnore/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname);

0 comments on commit d20a205

Please sign in to comment.