Skip to content

Commit

Permalink
Respecting prettiers default options (#549)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Janther and fvictorio authored Jul 8, 2021
1 parent 1da60ad commit c02436f
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coverage/**/*.js
tests/format/**/*.sol
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,3 +1,4 @@
coverage/**/*.js
tests/format/**/*.sol
tests/format/RespectDefaultOptions/respect-default-options.js
src/prettier-comments/**/*.js
44 changes: 41 additions & 3 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
const CATEGORY_GLOBAL = 'Global';
const CATEGORY_COMMON = 'Common';
const CATEGORY_SOLIDITY = 'Solidity';

const options = {
printWidth: {
since: '0.0.0',
category: CATEGORY_GLOBAL,
type: 'int',
default: 80,
description: 'The line length where Prettier will try wrap.',
range: { start: 0, end: Number.POSITIVE_INFINITY, step: 1 }
},
tabWidth: {
type: 'int',
category: CATEGORY_GLOBAL,
default: 2,
description: 'Number of spaces per indentation level.',
range: { start: 0, end: Number.POSITIVE_INFINITY, step: 1 }
},
useTabs: {
since: '1.0.0',
category: CATEGORY_GLOBAL,
type: 'boolean',
default: false,
description: 'Indent with tabs instead of spaces.'
},
bracketSpacing: {
since: '0.0.0',
category: CATEGORY_COMMON,
type: 'boolean',
default: true,
description: 'Print spaces between brackets.',
oppositeDescription: 'Do not print spaces between brackets.'
},
singleQuote: {
since: '0.0.0',
category: CATEGORY_COMMON,
type: 'boolean',
default: false,
description: 'Use single quotes instead of double quotes.'
},
explicitTypes: {
category: CATEGORY_SOLIDITY,
type: 'choice',
Expand All @@ -9,12 +48,11 @@ const options = {
choices: [
{
value: 'always',
description:
'Prefer the explicit types `uint256`, `int256`, and `bytes1`.'
description: 'Prefer explicit types (`uint256`, `int256`, etc.)'
},
{
value: 'never',
description: 'Prefer the type aliases `uint`, `int`, and `byte`.'
description: 'Prefer type aliases (`uint`, `int`, etc.)'
},
{
value: 'preserve',
Expand Down
5 changes: 3 additions & 2 deletions tests/config/require-standalone.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"use strict";

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

module.exports = {
formatWithCursor(input, options) {
const $$$options = {
...options,
plugins: [solidityPlugin, ...(options.plugins || [])],
plugins: [babelPlugin, solidityPlugin, ...(options.plugins || [])],
};
return prettier.formatWithCursor(input, $$$options);
},
Expand All @@ -16,7 +17,7 @@ module.exports = {
parse(input, options, massage) {
const $$$options = {
...options,
plugins: [solidityPlugin, ...(options.plugins || [])],
plugins: [babelPlugin, solidityPlugin, ...(options.plugins || [])],
};
return prettier.__debug.parse(input, $$$options, massage);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`respect-default-options.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
function a() {
return {key:value};
}
=====================================output=====================================
function a() {
return { key: value };
}
================================================================================
`;
5 changes: 5 additions & 0 deletions tests/format/RespectDefaultOptions/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Standalone mode doesn't have default options.
// This has been reported https://github.com/prettier/prettier/issues/11107
const { TEST_STANDALONE } = process.env;
if (!TEST_STANDALONE) run_spec(__dirname, ['babel']);
else test.todo.skip("Standalone mode doesn't have default options.");
3 changes: 3 additions & 0 deletions tests/format/RespectDefaultOptions/respect-default-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function a() {
return {key:value};
}

0 comments on commit c02436f

Please sign in to comment.