prettier-plugin-solidity 1.0.0-rc.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +47 -13
  2. package/dist/standalone.js +3 -0
  3. package/dist/standalone.js.LICENSE.txt +15 -0
  4. package/dist/standalone.js.map +1 -0
  5. package/package.json +42 -11
  6. package/src/common/util.js +59 -0
  7. package/src/nodes/HexLiteral.js +1 -1
  8. package/src/nodes/ImportDirective.js +5 -4
  9. package/src/nodes/InlineAssemblyStatement.js +1 -1
  10. package/src/nodes/SourceUnit.js +1 -1
  11. package/src/nodes/StringLiteral.js +1 -1
  12. package/src/parser.js +6 -5
  13. package/src/prettier-comments/language-js/comments.js +12 -10
  14. package/src/printer.js +3 -3
  15. package/.eslintignore +0 -5
  16. package/.eslintrc +0 -9
  17. package/.nvmrc +0 -1
  18. package/.prettierignore +0 -4
  19. package/.prettierrc +0 -4
  20. package/CODE_OF_CONDUCT.md +0 -76
  21. package/HOW_TO_PUBLISH.md +0 -39
  22. package/STYLEGUIDE.md +0 -382
  23. package/coverage/clover.xml +0 -1171
  24. package/coverage/coverage-final.json +0 -99
  25. package/coverage/lcov-report/base.css +0 -224
  26. package/coverage/lcov-report/block-navigation.js +0 -87
  27. package/coverage/lcov-report/favicon.png +0 -0
  28. package/coverage/lcov-report/index.html +0 -176
  29. package/coverage/lcov-report/prettify.css +0 -1
  30. package/coverage/lcov-report/prettify.js +0 -2
  31. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  32. package/coverage/lcov-report/sorter.js +0 -196
  33. package/coverage/lcov-report/src/binary-operator-printers/arithmetic.js.html +0 -244
  34. package/coverage/lcov-report/src/binary-operator-printers/assignment.js.html +0 -175
  35. package/coverage/lcov-report/src/binary-operator-printers/bit.js.html +0 -103
  36. package/coverage/lcov-report/src/binary-operator-printers/comparison.js.html +0 -199
  37. package/coverage/lcov-report/src/binary-operator-printers/exponentiation.js.html +0 -148
  38. package/coverage/lcov-report/src/binary-operator-printers/index.html +0 -221
  39. package/coverage/lcov-report/src/binary-operator-printers/index.js.html +0 -124
  40. package/coverage/lcov-report/src/binary-operator-printers/logical.js.html +0 -208
  41. package/coverage/lcov-report/src/binary-operator-printers/shift.js.html +0 -103
  42. package/coverage/lcov-report/src/clean.js.html +0 -109
  43. package/coverage/lcov-report/src/comments/handler.js.html +0 -373
  44. package/coverage/lcov-report/src/comments/handlers/handleContractDefinitionComments.js.html +0 -265
  45. package/coverage/lcov-report/src/comments/handlers/handleModifierInvocationComments.js.html +0 -292
  46. package/coverage/lcov-report/src/comments/handlers/index.html +0 -146
  47. package/coverage/lcov-report/src/comments/handlers/index.js.html +0 -103
  48. package/coverage/lcov-report/src/comments/ignore.js.html +0 -184
  49. package/coverage/lcov-report/src/comments/index.html +0 -161
  50. package/coverage/lcov-report/src/comments/index.js.html +0 -97
  51. package/coverage/lcov-report/src/comments/printer.js.html +0 -277
  52. package/coverage/lcov-report/src/index.html +0 -191
  53. package/coverage/lcov-report/src/index.js.html +0 -268
  54. package/coverage/lcov-report/src/loc.js.html +0 -133
  55. package/coverage/lcov-report/src/nodes/ArrayTypeName.js.html +0 -115
  56. package/coverage/lcov-report/src/nodes/AssemblyAssignment.js.html +0 -130
  57. package/coverage/lcov-report/src/nodes/AssemblyBlock.js.html +0 -160
  58. package/coverage/lcov-report/src/nodes/AssemblyCall.js.html +0 -133
  59. package/coverage/lcov-report/src/nodes/AssemblyCase.js.html +0 -112
  60. package/coverage/lcov-report/src/nodes/AssemblyFor.js.html +0 -139
  61. package/coverage/lcov-report/src/nodes/AssemblyFunctionDefinition.js.html +0 -184
  62. package/coverage/lcov-report/src/nodes/AssemblyIf.js.html +0 -115
  63. package/coverage/lcov-report/src/nodes/AssemblyLocalDefinition.js.html +0 -160
  64. package/coverage/lcov-report/src/nodes/AssemblyMemberAccess.js.html +0 -112
  65. package/coverage/lcov-report/src/nodes/AssemblyStackAssignment.js.html +0 -112
  66. package/coverage/lcov-report/src/nodes/AssemblySwitch.js.html +0 -133
  67. package/coverage/lcov-report/src/nodes/BinaryOperation.js.html +0 -127
  68. package/coverage/lcov-report/src/nodes/Block.js.html +0 -166
  69. package/coverage/lcov-report/src/nodes/BooleanLiteral.js.html +0 -100
  70. package/coverage/lcov-report/src/nodes/Break.js.html +0 -100
  71. package/coverage/lcov-report/src/nodes/BreakStatement.js.html +0 -100
  72. package/coverage/lcov-report/src/nodes/CatchClause.js.html +0 -148
  73. package/coverage/lcov-report/src/nodes/Conditional.js.html +0 -151
  74. package/coverage/lcov-report/src/nodes/Continue.js.html +0 -100
  75. package/coverage/lcov-report/src/nodes/ContinueStatement.js.html +0 -100
  76. package/coverage/lcov-report/src/nodes/ContractDefinition.js.html +0 -226
  77. package/coverage/lcov-report/src/nodes/CustomErrorDefinition.js.html +0 -139
  78. package/coverage/lcov-report/src/nodes/DecimalNumber.js.html +0 -100
  79. package/coverage/lcov-report/src/nodes/DoWhileStatement.js.html +0 -157
  80. package/coverage/lcov-report/src/nodes/ElementaryTypeName.js.html +0 -115
  81. package/coverage/lcov-report/src/nodes/EmitStatement.js.html +0 -100
  82. package/coverage/lcov-report/src/nodes/EnumDefinition.js.html +0 -151
  83. package/coverage/lcov-report/src/nodes/EnumValue.js.html +0 -100
  84. package/coverage/lcov-report/src/nodes/EventDefinition.js.html +0 -145
  85. package/coverage/lcov-report/src/nodes/ExpressionStatement.js.html +0 -181
  86. package/coverage/lcov-report/src/nodes/FileLevelConstant.js.html +0 -121
  87. package/coverage/lcov-report/src/nodes/ForStatement.js.html +0 -223
  88. package/coverage/lcov-report/src/nodes/FunctionCall.js.html +0 -280
  89. package/coverage/lcov-report/src/nodes/FunctionDefinition.js.html +0 -457
  90. package/coverage/lcov-report/src/nodes/FunctionTypeName.js.html +0 -217
  91. package/coverage/lcov-report/src/nodes/HexLiteral.js.html +0 -133
  92. package/coverage/lcov-report/src/nodes/HexNumber.js.html +0 -100
  93. package/coverage/lcov-report/src/nodes/Identifier.js.html +0 -100
  94. package/coverage/lcov-report/src/nodes/IfStatement.js.html +0 -265
  95. package/coverage/lcov-report/src/nodes/ImportDirective.js.html +0 -247
  96. package/coverage/lcov-report/src/nodes/IndexAccess.js.html +0 -199
  97. package/coverage/lcov-report/src/nodes/IndexRangeAccess.js.html +0 -121
  98. package/coverage/lcov-report/src/nodes/InheritanceSpecifier.js.html +0 -130
  99. package/coverage/lcov-report/src/nodes/InlineAssemblyStatement.js.html +0 -148
  100. package/coverage/lcov-report/src/nodes/LabelDefinition.js.html +0 -118
  101. package/coverage/lcov-report/src/nodes/Mapping.js.html +0 -118
  102. package/coverage/lcov-report/src/nodes/MemberAccess.js.html +0 -466
  103. package/coverage/lcov-report/src/nodes/ModifierDefinition.js.html +0 -259
  104. package/coverage/lcov-report/src/nodes/ModifierInvocation.js.html +0 -190
  105. package/coverage/lcov-report/src/nodes/NameValueExpression.js.html +0 -115
  106. package/coverage/lcov-report/src/nodes/NameValueList.js.html +0 -148
  107. package/coverage/lcov-report/src/nodes/NewExpression.js.html +0 -100
  108. package/coverage/lcov-report/src/nodes/NumberLiteral.js.html +0 -109
  109. package/coverage/lcov-report/src/nodes/PragmaDirective.js.html +0 -100
  110. package/coverage/lcov-report/src/nodes/ReturnStatement.js.html +0 -157
  111. package/coverage/lcov-report/src/nodes/RevertStatement.js.html +0 -100
  112. package/coverage/lcov-report/src/nodes/SourceUnit.js.html +0 -133
  113. package/coverage/lcov-report/src/nodes/StateVariableDeclaration.js.html +0 -166
  114. package/coverage/lcov-report/src/nodes/StringLiteral.js.html +0 -148
  115. package/coverage/lcov-report/src/nodes/StructDefinition.js.html +0 -154
  116. package/coverage/lcov-report/src/nodes/ThrowStatement.js.html +0 -100
  117. package/coverage/lcov-report/src/nodes/TryStatement.js.html +0 -214
  118. package/coverage/lcov-report/src/nodes/TupleExpression.js.html +0 -160
  119. package/coverage/lcov-report/src/nodes/TypeDefinition.js.html +0 -100
  120. package/coverage/lcov-report/src/nodes/UnaryOperation.js.html +0 -121
  121. package/coverage/lcov-report/src/nodes/UncheckedStatement.js.html +0 -118
  122. package/coverage/lcov-report/src/nodes/UserDefinedTypeName.js.html +0 -100
  123. package/coverage/lcov-report/src/nodes/UsingForDeclaration.js.html +0 -166
  124. package/coverage/lcov-report/src/nodes/VariableDeclaration.js.html +0 -253
  125. package/coverage/lcov-report/src/nodes/VariableDeclarationStatement.js.html +0 -217
  126. package/coverage/lcov-report/src/nodes/WhileStatement.js.html +0 -154
  127. package/coverage/lcov-report/src/nodes/index.html +0 -1256
  128. package/coverage/lcov-report/src/nodes/index.js.html +0 -319
  129. package/coverage/lcov-report/src/nodes/print-comments.js.html +0 -166
  130. package/coverage/lcov-report/src/nodes/print-preserving-empty-lines.js.html +0 -244
  131. package/coverage/lcov-report/src/nodes/print-separated-item.js.html +0 -148
  132. package/coverage/lcov-report/src/nodes/print-separated-list.js.html +0 -154
  133. package/coverage/lcov-report/src/options.js.html +0 -238
  134. package/coverage/lcov-report/src/parser.js.html +0 -643
  135. package/coverage/lcov-report/src/printer.js.html +0 -214
  136. package/coverage/lcov.info +0 -2672
  137. package/jest.config.js +0 -40
  138. package/src/prettier-comments/common/util.js +0 -684
package/package.json CHANGED
@@ -1,17 +1,31 @@
1
1
  {
2
2
  "name": "prettier-plugin-solidity",
3
- "version": "1.0.0-rc.1",
3
+ "version": "1.1.0",
4
4
  "description": "A Prettier Plugin for automatically formatting your Solidity code.",
5
- "main": "src",
5
+ "main": "./src/index.js",
6
+ "browser": "./dist/standalone.js",
7
+ "unpkg": "./dist/standalone.js",
6
8
  "scripts": {
9
+ "build": "webpack --env production",
10
+ "build:dev": "webpack --env development",
7
11
  "eslint": "eslint 'scripts/**' 'src/**' 'tests/**'",
8
12
  "generateindexes": "cross-env SCRIPT=true node scripts/generateIndexes.js",
9
13
  "lint": "npm run eslint && npm run prettier -- --list-different",
10
14
  "lint:fix": "npm run eslint -- --fix && npm run prettier -- --write",
15
+ "prepublishOnly": "npm run build",
11
16
  "prettier": "prettier './*.{js,json,md,yml}' '{scripts,src,tests}/**/*.js'",
12
17
  "test": "jest",
13
- "test:all": "cross-env FULL_TEST=1 jest"
18
+ "test:all": "cross-env FULL_TEST=1 c8 jest",
19
+ "test:standalone": "cross-env TEST_STANDALONE=1 FULL_TEST=1 jest"
14
20
  },
21
+ "files": [
22
+ "src",
23
+ "dist/standalone.js",
24
+ "dist/standalone.js.LICENSE.txt",
25
+ "dist/standalone.js.map",
26
+ "LICENSE",
27
+ "README.md"
28
+ ],
15
29
  "repository": {
16
30
  "type": "git",
17
31
  "url": "git+https://github.com/prettier-solidity/prettier-plugin-solidity.git"
@@ -66,31 +80,48 @@
66
80
  },
67
81
  "devDependencies": {
68
82
  "@babel/code-frame": "^7.18.6",
83
+ "c8": "^7.12.0",
69
84
  "cross-env": "^7.0.3",
70
85
  "dir-to-object": "^2.0.0",
71
- "eslint": "^8.21.0",
86
+ "eslint": "^8.29.0",
72
87
  "eslint-config-airbnb-base": "^15.0.0",
73
88
  "eslint-config-prettier": "^8.5.0",
74
89
  "eslint-plugin-import": "^2.26.0",
75
- "jest": "^29.0.1",
90
+ "exports-loader": "^4.0.0",
91
+ "jest": "^29.3.1",
92
+ "jest-light-runner": "^0.4.1",
76
93
  "jest-mock-now": "^1.3.0",
77
94
  "jest-snapshot-serializer-ansi": "^1.0.0",
78
95
  "jest-snapshot-serializer-raw": "^1.2.0",
79
- "jest-watch-typeahead": "^2.0.0",
96
+ "jest-watch-typeahead": "^2.2.1",
80
97
  "lines-and-columns": "^2.0.3",
81
- "outdent": "^0.8.0",
82
- "prettier": "^2.7.1",
83
- "solc": "^0.8.17"
98
+ "prettier": "^2.8.1",
99
+ "proxyquire": "^2.1.3",
100
+ "solc": "^0.8.17",
101
+ "webpack": "^5.75.0",
102
+ "webpack-cli": "^5.0.1"
84
103
  },
85
104
  "dependencies": {
86
105
  "@solidity-parser/parser": "^0.14.5",
87
- "emoji-regex": "^10.1.0",
106
+ "emoji-regex": "^10.2.1",
88
107
  "escape-string-regexp": "^4.0.0",
89
- "semver": "^7.3.7",
108
+ "semver": "^7.3.8",
90
109
  "solidity-comments-extractor": "^0.0.7",
91
110
  "string-width": "^4.2.3"
92
111
  },
93
112
  "peerDependencies": {
94
113
  "prettier": "^2.3.0"
114
+ },
115
+ "browserslist": {
116
+ "production": [
117
+ ">0.2%",
118
+ "not dead",
119
+ "not op_mini all"
120
+ ],
121
+ "development": [
122
+ "last 1 chrome version",
123
+ "last 1 firefox version",
124
+ "last 1 safari version"
125
+ ]
95
126
  }
96
127
  }
@@ -0,0 +1,59 @@
1
+ const {
2
+ util: { getNextNonSpaceNonCommentCharacterIndex, makeString }
3
+ } = require('prettier');
4
+
5
+ function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
6
+ return text.charAt(
7
+ getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
8
+ );
9
+ }
10
+
11
+ function printString(rawContent, options) {
12
+ const double = { quote: '"', regex: /"/g };
13
+ const single = { quote: "'", regex: /'/g };
14
+
15
+ const preferred = options.singleQuote ? single : double;
16
+ const alternate = preferred === single ? double : single;
17
+
18
+ let shouldUseAlternateQuote = false;
19
+
20
+ // If `rawContent` contains at least one of the quote preferred for enclosing
21
+ // the string, we might want to enclose with the alternate quote instead, to
22
+ // minimize the number of escaped quotes.
23
+ // Also check for the alternate quote, to determine if we're allowed to swap
24
+ // the quotes on a DirectiveLiteral.
25
+ if (
26
+ rawContent.includes(preferred.quote) ||
27
+ rawContent.includes(alternate.quote)
28
+ ) {
29
+ const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
30
+ const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
31
+
32
+ shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
33
+ }
34
+
35
+ const enclosingQuote = shouldUseAlternateQuote
36
+ ? alternate.quote
37
+ : preferred.quote;
38
+
39
+ // It might sound unnecessary to use `makeString` even if the string already
40
+ // is enclosed with `enclosingQuote`, but it isn't. The string could contain
41
+ // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
42
+ // sure that we consistently output the minimum amount of escaped quotes.
43
+ return makeString(rawContent, enclosingQuote);
44
+ }
45
+
46
+ function hasNodeIgnoreComment(node) {
47
+ return (
48
+ node &&
49
+ node.comments &&
50
+ node.comments.length > 0 &&
51
+ node.comments.some((comment) => comment.value.trim() === 'prettier-ignore')
52
+ );
53
+ }
54
+
55
+ module.exports = {
56
+ getNextNonSpaceNonCommentCharacter,
57
+ printString,
58
+ hasNodeIgnoreComment
59
+ };
@@ -4,7 +4,7 @@ const {
4
4
  }
5
5
  } = require('prettier');
6
6
 
7
- const { printString } = require('../prettier-comments/common/util');
7
+ const { printString } = require('../common/util');
8
8
 
9
9
  const HexLiteral = {
10
10
  print: ({ node, options }) => {
@@ -3,10 +3,11 @@ const {
3
3
  builders: { group, line, softline }
4
4
  }
5
5
  } = require('prettier');
6
- const semver = require('semver');
6
+ const coerce = require('semver/functions/coerce');
7
+ const satisfies = require('semver/functions/satisfies');
7
8
 
8
9
  const printSeparatedList = require('./print-separated-list');
9
- const { printString } = require('../prettier-comments/common/util');
10
+ const { printString } = require('../common/util');
10
11
 
11
12
  const ImportDirective = {
12
13
  print: ({ node, options }) => {
@@ -18,14 +19,14 @@ const ImportDirective = {
18
19
  doc = [importPath, ' as ', node.unitAlias];
19
20
  } else if (node.symbolAliases) {
20
21
  // import { Foo, Bar as Qux } from "./Foo.sol";
21
- const compiler = semver.coerce(options.compiler);
22
+ const compiler = coerce(options.compiler);
22
23
  const symbolAliases = node.symbolAliases.map(([a, b]) =>
23
24
  b ? `${a} as ${b}` : a
24
25
  );
25
26
  let firstSeparator;
26
27
  let separator;
27
28
 
28
- if (compiler && semver.satisfies(compiler, '>=0.7.4')) {
29
+ if (compiler && satisfies(compiler, '>=0.7.4')) {
29
30
  // if the compiler exists and is greater than or equal to 0.7.4 we will
30
31
  // split the ImportDirective.
31
32
  firstSeparator = options.bracketSpacing ? line : softline;
@@ -1,5 +1,5 @@
1
1
  // @TODO: add support for assembly language specifier
2
- const { printString } = require('../prettier-comments/common/util');
2
+ const { printString } = require('../common/util');
3
3
  const printSeparatedList = require('./print-separated-list');
4
4
 
5
5
  const InlineAssemblyStatement = {
@@ -9,7 +9,7 @@ const printPreservingEmptyLines = require('./print-preserving-empty-lines');
9
9
  const SourceUnit = {
10
10
  print: ({ options, path, print }) => [
11
11
  printPreservingEmptyLines(path, 'children', options, print),
12
- line
12
+ options.parentParser ? '' : line
13
13
  ]
14
14
  };
15
15
 
@@ -3,7 +3,7 @@ const {
3
3
  builders: { join, hardline }
4
4
  }
5
5
  } = require('prettier');
6
- const { printString } = require('../prettier-comments/common/util');
6
+ const { printString } = require('../common/util');
7
7
 
8
8
  const StringLiteral = {
9
9
  print: ({ node, options }) => {
package/src/parser.js CHANGED
@@ -1,7 +1,8 @@
1
1
  const extractComments = require('solidity-comments-extractor');
2
2
  // https://prettier.io/docs/en/plugins.html#parsers
3
3
  const parser = require('@solidity-parser/parser');
4
- const semver = require('semver');
4
+ const coerce = require('semver/functions/coerce');
5
+ const satisfies = require('semver/functions/satisfies');
5
6
 
6
7
  const tryHug = (node, operators) => {
7
8
  if (node.type === 'BinaryOperation' && operators.includes(node.operator))
@@ -14,7 +15,7 @@ const tryHug = (node, operators) => {
14
15
  };
15
16
 
16
17
  function parse(text, _parsers, options) {
17
- const compiler = semver.coerce(options.compiler);
18
+ const compiler = coerce(options.compiler);
18
19
  const parsed = parser.parse(text, { loc: true, range: true });
19
20
  parsed.comments = extractComments(text);
20
21
 
@@ -25,7 +26,7 @@ function parse(text, _parsers, options) {
25
26
  // if the compiler option has not been provided we leave.
26
27
  if (!compiler) return;
27
28
  // we make a check against each pragma directive in the document.
28
- if (!semver.satisfies(compiler, ctx.value)) {
29
+ if (!satisfies(compiler, ctx.value)) {
29
30
  // @TODO: investigate the best way to warn that would apply to
30
31
  // different editors.
31
32
  // eslint-disable-next-line no-console
@@ -64,7 +65,7 @@ function parse(text, _parsers, options) {
64
65
  // if the compiler is below 0.8.0 we will recognize the type 'byte' as an
65
66
  // alias of 'bytes1'. Otherwise we will ignore this and enforce always
66
67
  // 'bytes1'.
67
- const pre080 = compiler && semver.satisfies(compiler, '<0.8.0');
68
+ const pre080 = compiler && satisfies(compiler, '<0.8.0');
68
69
  if (!pre080 && ctx.name === 'byte') ctx.name = 'bytes1';
69
70
  },
70
71
  BinaryOperation(ctx) {
@@ -87,7 +88,7 @@ function parse(text, _parsers, options) {
87
88
  // If the compiler has not been given as an option using we leave a**b**c.
88
89
  if (!compiler) break;
89
90
 
90
- if (semver.satisfies(compiler, '<0.8.0')) {
91
+ if (satisfies(compiler, '<0.8.0')) {
91
92
  // If the compiler is less than 0.8.0 then a**b**c is formatted as
92
93
  // (a**b)**c.
93
94
  ctx.left = tryHug(ctx.left, ['**']);
@@ -5,10 +5,12 @@ const {
5
5
  addLeadingComment,
6
6
  addTrailingComment,
7
7
  addDanglingComment,
8
- getNextNonSpaceNonCommentCharacterIndex
8
+ getNextNonSpaceNonCommentCharacterIndex,
9
+ hasNewline,
10
+ hasNewlineInRange
9
11
  }
10
12
  } = require('prettier');
11
- const privateUtil = require("../common/util");
13
+ const { getNextNonSpaceNonCommentCharacter } = require("../../common/util");
12
14
 
13
15
  function handleOwnLineComment(comment, text, options, ast, isLastComment) {
14
16
  const { precedingNode, enclosingNode, followingNode } = comment;
@@ -241,7 +243,7 @@ function handleIfStatementComments(
241
243
  // if (a /* comment */) {}
242
244
  // The only workaround I found is to look at the next character to see if
243
245
  // it is a ).
244
- const nextCharacter = privateUtil.getNextNonSpaceNonCommentCharacter(
246
+ const nextCharacter = getNextNonSpaceNonCommentCharacter(
245
247
  text,
246
248
  comment,
247
249
  options.locEnd
@@ -310,7 +312,7 @@ function handleWhileComments(
310
312
  // while (a /* comment */) {}
311
313
  // The only workaround I found is to look at the next character to see if
312
314
  // it is a ).
313
- const nextCharacter = privateUtil.getNextNonSpaceNonCommentCharacter(
315
+ const nextCharacter = getNextNonSpaceNonCommentCharacter(
314
316
  text,
315
317
  comment,
316
318
  options.locEnd
@@ -391,7 +393,7 @@ function handleConditionalExpressionComments(
391
393
  ) {
392
394
  const isSameLineAsPrecedingNode =
393
395
  precedingNode &&
394
- !privateUtil.hasNewlineInRange(
396
+ !hasNewlineInRange(
395
397
  text,
396
398
  options.locEnd(precedingNode),
397
399
  options.locStart(comment)
@@ -469,7 +471,7 @@ function handleMethodNameComments(
469
471
  enclosingNode.key === precedingNode &&
470
472
  // special Property case: { key: /*comment*/(value) };
471
473
  // comment should be attached to value instead of key
472
- privateUtil.getNextNonSpaceNonCommentCharacter(
474
+ getNextNonSpaceNonCommentCharacter(
473
475
  text,
474
476
  precedingNode,
475
477
  options.locEnd
@@ -506,7 +508,7 @@ function handleFunctionNameComments(
506
508
  options
507
509
  ) {
508
510
  if (
509
- privateUtil.getNextNonSpaceNonCommentCharacter(
511
+ getNextNonSpaceNonCommentCharacter(
510
512
  text,
511
513
  comment,
512
514
  options.locEnd
@@ -550,7 +552,7 @@ function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
550
552
 
551
553
  function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
552
554
  if (
553
- privateUtil.getNextNonSpaceNonCommentCharacter(
555
+ getNextNonSpaceNonCommentCharacter(
554
556
  text,
555
557
  comment,
556
558
  options.locEnd
@@ -621,7 +623,7 @@ function handleLastFunctionArgComments(
621
623
  enclosingNode.type === "FunctionDeclaration" ||
622
624
  enclosingNode.type === "ObjectMethod" ||
623
625
  enclosingNode.type === "ClassMethod") &&
624
- privateUtil.getNextNonSpaceNonCommentCharacter(
626
+ getNextNonSpaceNonCommentCharacter(
625
627
  text,
626
628
  comment,
627
629
  options.locEnd
@@ -755,7 +757,7 @@ function handleImportDeclarationComments(
755
757
  precedingNode.type === "ImportSpecifier" &&
756
758
  enclosingNode &&
757
759
  enclosingNode.type === "ImportDeclaration" &&
758
- privateUtil.hasNewline(text, options.locEnd(comment))
760
+ hasNewline(text, options.locEnd(comment))
759
761
  ) {
760
762
  addTrailingComment(precedingNode, comment);
761
763
  return true;
package/src/printer.js CHANGED
@@ -1,14 +1,14 @@
1
1
  const prettier = require('prettier');
2
- const semver = require('semver');
2
+ const satisfies = require('semver/functions/satisfies');
3
3
  const nodes = require('./nodes');
4
- const { hasNodeIgnoreComment } = require('./prettier-comments/common/util');
4
+ const { hasNodeIgnoreComment } = require('./common/util');
5
5
  const ignoreComments = require('./comments/ignore');
6
6
 
7
7
  let checked = false;
8
8
 
9
9
  function prettierVersionCheck() {
10
10
  if (checked) return;
11
- if (!semver.satisfies(prettier.version, '>=2.3.0')) {
11
+ if (!satisfies(prettier.version, '>=2.3.0')) {
12
12
  throw new Error(
13
13
  'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
14
14
  );
package/.eslintignore DELETED
@@ -1,5 +0,0 @@
1
- coverage/**/*.js
2
- tests/format/**/*.sol
3
- tests/format/RespectDefaultOptions/respect-default-options.js
4
- tests/config/**/*.js
5
- src/prettier-comments/**/*.js
package/.eslintrc DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "env": {
3
- "jest": true
4
- },
5
- "extends": ["airbnb-base", "prettier"],
6
- "globals": {
7
- "run_spec": false
8
- }
9
- }
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 14
package/.prettierignore DELETED
@@ -1,4 +0,0 @@
1
- coverage/**/*.js
2
- tests/format/**/*.sol
3
- tests/format/RespectDefaultOptions/respect-default-options.js
4
- src/prettier-comments/**/*.js
package/.prettierrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "singleQuote": true,
3
- "trailingComma": "none"
4
- }
@@ -1,76 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, sex characteristics, gender identity and expression,
9
- level of experience, education, socioeconomic status, nationality, personal
10
- appearance, race, religion, or sexual identity and orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- - Using welcoming and inclusive language
18
- - Being respectful of differing viewpoints and experiences
19
- - Gracefully accepting constructive criticism
20
- - Focusing on what is best for the community
21
- - Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- - The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- - Trolling, insulting/derogatory comments, and personal or political attacks
28
- - Public or private harassment
29
- - Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- - Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at mattia.richetto@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
-
73
- [homepage]: https://www.contributor-covenant.org
74
-
75
- For answers to common questions about this code of conduct, see
76
- https://www.contributor-covenant.org/faq
package/HOW_TO_PUBLISH.md DELETED
@@ -1,39 +0,0 @@
1
- # How to publish
2
-
3
- ```bash
4
- nvm use
5
-
6
- git checkout main
7
-
8
- git pull
9
-
10
- npm i
11
-
12
- npm run test:all
13
- ```
14
-
15
- - Create a branch with the name of the new version number, e.g.: `git checkout -b 1.0.0-beta.4`
16
-
17
- - Bump the version in the package.json file
18
-
19
- - `npm i`
20
-
21
- ```bash
22
- git add .
23
-
24
- git commit -m 'bump version'
25
-
26
- git push
27
- ```
28
-
29
- - Once the PR is merged, then `git checkout main` and `git pull`
30
-
31
- - Uncomment the first line of the `.npmrc` file and comment the second line
32
-
33
- - Then publish the package using the following command: `NPM_TOKEN=${NPM_TOKEN} npm publish`
34
-
35
- > N.B.: you need to replace `${NPM_TOKEN}` with a valid npm token
36
-
37
- - Once the new version is published, add a new release in GitHub; https://github.com/prettier-solidity/prettier-plugin-solidity/releases/new
38
-
39
- - The tag version and the name should be prefixed by a `v` followed by the latest published version number; e.g.: `v1.0.0-beta.4`