Skip to content

Commit c02436f

Browse files
Jantherfvictorio
andauthored
Respecting prettiers default options (#549)
* having all options defined in our options object and making sure the defaults are being respected. See #375 * not using `byte` anymore * No testing when the js format on StandAlone * Update options.js Co-authored-by: Franco Victorio <[email protected]>
1 parent 1da60ad commit c02436f

7 files changed

Lines changed: 73 additions & 5 deletions

File tree

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
coverage/**/*.js
22
tests/format/**/*.sol
3+
tests/format/RespectDefaultOptions/respect-default-options.js
34
tests/config/**/*.js
45
src/prettier-comments/**/*.js

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
coverage/**/*.js
22
tests/format/**/*.sol
3+
tests/format/RespectDefaultOptions/respect-default-options.js
34
src/prettier-comments/**/*.js

src/options.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
1+
const CATEGORY_GLOBAL = 'Global';
2+
const CATEGORY_COMMON = 'Common';
13
const CATEGORY_SOLIDITY = 'Solidity';
24

35
const options = {
6+
printWidth: {
7+
since: '0.0.0',
8+
category: CATEGORY_GLOBAL,
9+
type: 'int',
10+
default: 80,
11+
description: 'The line length where Prettier will try wrap.',
12+
range: { start: 0, end: Number.POSITIVE_INFINITY, step: 1 }
13+
},
14+
tabWidth: {
15+
type: 'int',
16+
category: CATEGORY_GLOBAL,
17+
default: 2,
18+
description: 'Number of spaces per indentation level.',
19+
range: { start: 0, end: Number.POSITIVE_INFINITY, step: 1 }
20+
},
21+
useTabs: {
22+
since: '1.0.0',
23+
category: CATEGORY_GLOBAL,
24+
type: 'boolean',
25+
default: false,
26+
description: 'Indent with tabs instead of spaces.'
27+
},
28+
bracketSpacing: {
29+
since: '0.0.0',
30+
category: CATEGORY_COMMON,
31+
type: 'boolean',
32+
default: true,
33+
description: 'Print spaces between brackets.',
34+
oppositeDescription: 'Do not print spaces between brackets.'
35+
},
36+
singleQuote: {
37+
since: '0.0.0',
38+
category: CATEGORY_COMMON,
39+
type: 'boolean',
40+
default: false,
41+
description: 'Use single quotes instead of double quotes.'
42+
},
443
explicitTypes: {
544
category: CATEGORY_SOLIDITY,
645
type: 'choice',
@@ -9,12 +48,11 @@ const options = {
948
choices: [
1049
{
1150
value: 'always',
12-
description:
13-
'Prefer the explicit types `uint256`, `int256`, and `bytes1`.'
51+
description: 'Prefer explicit types (`uint256`, `int256`, etc.)'
1452
},
1553
{
1654
value: 'never',
17-
description: 'Prefer the type aliases `uint`, `int`, and `byte`.'
55+
description: 'Prefer type aliases (`uint`, `int`, etc.)'
1856
},
1957
{
2058
value: 'preserve',

tests/config/require-standalone.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"use strict";
22

33
const prettier = require("prettier/standalone");
4+
const babelPlugin = require("prettier/parser-babel");
45
const solidityPlugin = require("../../src/index");
56

67
module.exports = {
78
formatWithCursor(input, options) {
89
const $$$options = {
910
...options,
10-
plugins: [solidityPlugin, ...(options.plugins || [])],
11+
plugins: [babelPlugin, solidityPlugin, ...(options.plugins || [])],
1112
};
1213
return prettier.formatWithCursor(input, $$$options);
1314
},
@@ -16,7 +17,7 @@ module.exports = {
1617
parse(input, options, massage) {
1718
const $$$options = {
1819
...options,
19-
plugins: [solidityPlugin, ...(options.plugins || [])],
20+
plugins: [babelPlugin, solidityPlugin, ...(options.plugins || [])],
2021
};
2122
return prettier.__debug.parse(input, $$$options, massage);
2223
},
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`respect-default-options.js format 1`] = `
4+
====================================options=====================================
5+
parsers: ["babel"]
6+
printWidth: 80
7+
| printWidth
8+
=====================================input======================================
9+
function a() {
10+
return {key:value};
11+
}
12+
13+
=====================================output=====================================
14+
function a() {
15+
return { key: value };
16+
}
17+
18+
================================================================================
19+
`;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Standalone mode doesn't have default options.
2+
// This has been reported https://github.com/prettier/prettier/issues/11107
3+
const { TEST_STANDALONE } = process.env;
4+
if (!TEST_STANDALONE) run_spec(__dirname, ['babel']);
5+
else test.todo.skip("Standalone mode doesn't have default options.");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function a() {
2+
return {key:value};
3+
}

0 commit comments

Comments
 (0)