{"id":13621137,"url":"https://github.com/sambacha/prettier-config-solidity","last_synced_at":"2025-04-30T17:22:09.044Z","repository":{"id":37083017,"uuid":"312459708","full_name":"sambacha/prettier-config-solidity","owner":"sambacha","description":"Prettier config optimized to reduce AST churn \u0026 conform to solidity spec","archived":false,"fork":false,"pushed_at":"2022-12-19T16:04:13.000Z","size":2490,"stargazers_count":30,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T16:13:11.392Z","etag":null,"topics":["config","defi","ethereum","prettier","prettier-config","solidity"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sambacha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-13T03:09:22.000Z","updated_at":"2025-02-14T15:52:54.000Z","dependencies_parsed_at":"2023-01-29T22:15:15.306Z","dependency_job_id":null,"html_url":"https://github.com/sambacha/prettier-config-solidity","commit_stats":null,"previous_names":["sambacha/prettier-solidity-config"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fprettier-config-solidity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fprettier-config-solidity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fprettier-config-solidity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fprettier-config-solidity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sambacha","download_url":"https://codeload.github.com/sambacha/prettier-config-solidity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251749135,"owners_count":21637459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","defi","ethereum","prettier","prettier-config","solidity"],"created_at":"2024-08-01T21:01:02.869Z","updated_at":"2025-04-30T17:22:08.993Z","avatar_url":"https://github.com/sambacha.png","language":"Solidity","funding_links":[],"categories":["Tools"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n \u003cbr\u003e\n prettier-config-solidity\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\na conformant prettier configuration for Solidity         \n\u003c/p\u003e\n\n[![nodejs](https://github.com/sambacha/prettier-config-solidity/actions/workflows/nodejs.yml/badge.svg)](https://github.com/sambacha/prettier-config-solidity/actions/workflows/nodejs.yml)\n[![codecov](https://codecov.io/gh/sambacha/prettier-solidity-config/branch/master/graph/badge.svg?token=1k3OYjAl8C)](https://codecov.io/gh/sambacha/prettier-solidity-config)\n\n- [Quickstart](#quickstart)\n- [Overview](#overview)\n- [Motivation](#motivation)\n  - [Reducing AST Churn](#whitespace)\n    - [whitespace](#whitespace)\n    - [arrow-parens](#arrow-parens)\n    - [one var](#one-var)\n- [Install](#install)\n  - [Prettier](#prettier)\n  - [with SolHint](#with-solhint)\n- [License](#license)\n\n## Quickstart\n\nSee the [dappspec format](https://github.com/sambacha/dappspec) for additional style guide directives \n\n#### Prettier \u0026 Plugin+Config\n\n\u003e**Warning**\n\u003eA Major Semver release for prettier is upcoming, ensure you are using compatible versions\n\n```bash\nnpm i -D prettier@^2 prettier-plugin-solidity@latest prettier-config-solidity@latest  --save-exact\n```\n\n\n#### create `prettier.config.js` file\n\n```javascript\n'use strict';\nconst prettierConfig = require('prettier-config-solidity');\nmodule.exports = prettierConfig;\n```\n\n#### Editorconfig \n\n```cfg\n# Stop the editor from looking for .editorconfig files in the parent directories\n# root = true\n\n[*]\n# Non-configurable Prettier behaviors\ncharset = utf-8\ninsert_final_newline = true\n# Caveat: Prettier won’t trim trailing whitespace inside template strings, but your editor might.\n# trim_trailing_whitespace = true\n\n# Configurable Prettier behaviors\n# (change these if your Prettier config differs)\nend_of_line = lf\nindent_style = space\nindent_size = 2\nmax_line_length = 80\n\n# Solidity\n# https://github.com/sambacha/prettier-config-solidity\n[*.sol]\nindent_size = 4\nindent_style = space\n\n# Ignore fixtures and vendored files\n[{dist,artifacts,vendor,test,fixtures,tests,cache,__snapshot__,}/**]\ncharset = unset\nend_of_line = unset\nindent_size = unset\nindent_style = unset\ninsert_final_newline = unset\ntrim_trailing_spaces = unset\n```\n\n## Style Convention\n\nExample:\n- Changes `unit` to `unit256`\n- \n\n### unformatted\n\n```solidity\n    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)\n        external\n        override\n        payable\n        ensure(deadline)\n        returns (uint[] memory amounts)\n    {\n```\n\n### formatted\n\n```solidity\n    function swapExactETHForTokens(\n        uint256 amountOutMin,\n        address[] calldata path,\n        address to,\n        uint256 deadline\n    ) external payable override ensure(deadline) returns (uint256[] memory amounts) {\n        require(path[0] == WETH, \"UniswapV2Router: INVALID_PATH\");\n```\n\n## Overview\n\nPrettier configuration for Solidity\n\n## Motivation\n\nThis configuration is optimized to reduce **diff churn** and improve AST\nresults.\n\nThe following rules are employed, with specific reasonings to their choice\n(source: airbnb style guide):\n\n## `printWidth`\n\nThe behavior of `printWidth` is located here:\n[prettier-solidity/prettier-plugin-solidity/blob/b504261047d0019c924d53a2b9ab0738b1e05703/src/nodes/FunctionDefinition.js#L99](https://github.com/prettier-solidity/prettier-plugin-solidity/blob/b504261047d0019c924d53a2b9ab0738b1e05703/src/nodes/FunctionDefinition.js#L99)\n\nSee more here\n[prettier-plugin-solidity/issues/474#issuecomment-823670541](https://github.com/prettier-solidity/prettier-plugin-solidity/issues/474#issuecomment-823670541)\n\n### whitespace\n\n[source@airbnb/javascript#whitespace--in-braces](https://github.com/airbnb/javascript#whitespace--in-braces)\n\n- 19.12 Add spaces inside curly braces. eslint: object-curly-spacing\n\n```jsx\n// bad\nconst foo = { clark: 'kent' };\n\n// good\nconst foo = { clark: 'kent' };\n```\n\n#### arrow-parens\n\n- 8.4 Always include parentheses around arguments for clarity and consistency.\n  eslint: arrow-parens\n\n[source@airbnb/javascript#arrows--one-arg-parens](https://github.com/airbnb/javascript#arrows--one-arg-parens)\n\n\u003e Why? Minimizes diff churn when adding or removing arguments.\n\n```jsx\n// bad\n[1, 2, 3].map((x) =\u003e x * x);\n\n// good\n[1, 2, 3].map((x) =\u003e x * x);\n\n// bad\n[1, 2, 3].map(\n  (number) =\u003e\n    `A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`,\n);\n\n// good\n[1, 2, 3].map(\n  (number) =\u003e\n    `A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`,\n);\n\n// bad\n[1, 2, 3].map((x) =\u003e {\n  const y = x + 1;\n  return x * y;\n});\n\n// good\n[1, 2, 3].map((x) =\u003e {\n  const y = x + 1;\n  return x * y;\n});\n```\n\n#### one var\n\n- 13.2 Use one const or let declaration per variable or assignment. eslint:\n  one-var\n\n\u003e Why? It’s easier to add new variable declarations this way, and you never have\n\u003e to worry about swapping out a ; for a , or introducing punctuation-only diffs.\n\u003e You can also step through each declaration with the debugger, instead of\n\u003e jumping through all of them at once.\n\n##### [ref:eslint/rules/one-var](https://eslint.org/docs/rules/one-var)\n\n```jsx\n// bad\nconst items = getItems(),\n  goSportsTeam = true,\n  dragonball = 'z';\n\n// bad\n// (compare to above, and try to spot the mistake)\nconst items = getItems(),\n  goSportsTeam = true;\ndragonball = 'z';\n\n// good\nconst items = getItems();\nconst goSportsTeam = true;\nconst dragonball = 'z';\n```\n\n#### 20.2 Additional trailing comma: Yup. eslint: comma-dangle\n\n    Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don’t have to worry about the trailing comma problem in legacy browsers.\n\n```diff\n// bad - git diff without trailing comma\nconst hero = {\n     firstName: 'Florence',\n-    lastName: 'Nightingale'\n+    lastName: 'Nightingale',\n+    inventorOf: ['coxcomb chart', 'modern nursing']\n};\n\n// good - git diff with trailing comma\nconst hero = {\n     firstName: 'Florence',\n     lastName: 'Nightingale',\n+    inventorOf: ['coxcomb chart', 'modern nursing'],\n};\n```\n\n#### 8.6 Enforce the location of arrow function bodies with implicit returns. eslint: implicit-arrow-linebreak\n\n```js\n// bad\n(foo) =\u003e bar;\n\n(foo) =\u003e bar;\n\n// good\n(foo) =\u003e bar;\n(foo) =\u003e bar;\n(foo) =\u003e bar;\n```\n\n## Install\n\n#### Prettier\n\n```bash\nnpm i -D prettier prettier-plugin-solidity@latest prettier-config-solidity  --save-exact\n```\n\n```bash\nnpm i -D prettier prettier-plugin-solidity@latest prettier-config-solidity  --save-exact --legacy-peer-deps\n```\n\nor\n\n```bash\nyarn add -D prettier prettier-plugin-solidity@latest prettier-config-solidity  --save-exact\n```\n\n#### with SolHint\n\n```bash\nnpm install --save-dev solhint solhint-plugin-prettier prettier prettier-plugin-solidity --save-exact\n```\n\n```json\n{\n  \"plugins\": [\"prettier\"],\n  \"rules\": {\n    \"prettier/prettier\": \"error\"\n  }\n}\n```\n\n## License\n\nSPDX-License-Identifier: Apache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsambacha%2Fprettier-config-solidity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsambacha%2Fprettier-config-solidity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsambacha%2Fprettier-config-solidity/lists"}