Replies: 3 comments 1 reply
-
|
Fully agree, ROS 2 coding style is a great example to follow as many developers do |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Nice work! For C++ I should also recommend using -Wall -Werror -pedantic as compilation flags within the CMake. Consider also take an eye on https://github.com/ament/ament_lint/blob/rolling/ament_cmake_lint_cmake/doc/index.rst |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Great job 👍 I'm totally onboard. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is the style guide for languages used in RA, RAM, and RI repositories.
Languages: Python, Javascript, C++, CMAKE, HTML, CSS, YAML, XML
This guide is heavily based on the ROS2 (Humble) Coding Style Guide
Python
flake8,blackpydocstyleC++
ament_cpplintandament_uncrustifyCMAKE
Summary
find_package, notFIND_PACKAGE).snake_caseidentifiers (variables, functions, macros).else()andend...()commands.(‘s.set(PARENT_SCOPE)to macros._or a reasonable prefix.ament_lint_cmakeJavascript
reactforjsxcomponents lintingjsonforJSONlintingeslintprettierBase ESLint Config
{ "extends": ["eslint:recommended", "prettier"], "env": { "browser": true, "es2021": true, "node": true }, "parserOptions": { "ecmaVersion": 12, "sourceType": "module" }, "rules": { // Add custom rules if needed } }HTML/CSS
eslint,stylelintprettierXML
xmllint/ament_xmllintYAML
yamllintyamlfmtHow To Setup Your IDE
Python
VSCode
settings.jsonfile{ // ... "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" }, "black-formatter.args": ["--line-length", "88"], "flake8.importStrategy": "fromEnvironment", "flake8.args": [ "--max-line-length=88", "--extend-ignore=E701,W503,E203", "--docstring-convention=pep257" ] // ... }PyCharm
flake8(details TBD)Javascript - HTML - CSS
VSCode
Install the prettier vscode extension
Install the eslint vscode extension
add the following
.prettierrcfile to the source code{ "printWidth": 80, "tabWidth": 2, "useTabs": false, "semi": true, "singleQuote": true, "trailingComma": "es5", "bracketSpacing": true, "arrowParens": "always", "endOfLine": "lf", "overrides": [ ] }.eslintrc.jsonto the source code{ "root": true, "env": { "browser": true, "node": true, "es2021": true }, "parserOptions": { "ecmaVersion": 2021, "sourceType": "module" }, "extends": [ "eslint:recommended", "plugin:prettier/recommended" ], "plugins": ["prettier", "@html-eslint", "yml"], "overrides": [ // { // "files": ["*.ts", "*.tsx"], // "parser": "@typescript-eslint/parser" // }, { "files": ["**/*.html"], "parser": "@html-eslint/parser" }, { "files": ["*.css", "*.scss"] }, { "files": ["*.yml", "*.yaml"], "extends": ["plugin:yml/recommended"] } ], "rules": { "indent": ["error", 2], "quotes": ["error", "single"], "semi": ["error", "always"] // "@typescript-eslint/no-unused-vars": "warn" } }CSS
stylelintneeded modules.stylelintrc.jsonto your source code{ "extends": ["stylelint-config-standard"] }YAML
.prettierrcfile to the projects source code{ "printWidth": 80, "tabWidth": 2, "useTabs": false, "semi": true, "singleQuote": true, "trailingComma": "es5", "bracketSpacing": true, "arrowParens": "always", "endOfLine": "lf", "overrides": [ { "files": ["*.yaml", "*.yml"], "options": { "singleQuote": false } } ] }settings.jsonfile{ // ... "editor.formatOnSave": true, "[yaml]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, // "prettier.printWidth": 80, "prettier.tabWidth": 2, "prettier.useTabs": false, "prettier.semi": true, "prettier.singleQuote": true, "prettier.trailingComma": "es5", "prettier.bracketSpacing": true, "prettier.arrowParens": "always", "prettier.endOfLine": "lf", // "[yaml]": { "prettier.singleQuote": false } // ... }XML
VSCode
settings.jsonfile{ // "[xml]": { "editor.defaultFormatter": "redhat.vscode-xml" }, "xml.format.enabled": true, "xml.preferences.quoteStyle": "double", "xml.format.enforceQuoteStyle": "preferred", "xml.format.maxLineWidth": 80 // }C++
VSCode
cpplintanduncrustify(Ubuntu)settings.jsonfilewhich cpplintto find<your-cpplint-path>{ // "cpplint.cpplintPath": "<your-cpplint-path>", "cpplint.lineLength": 100, "cpplint.filters": [ "-build/include_subdir", "-whitespace/braces", "-build/namespaces", "-whitespace/indent", "-whitespace/indent_namespace", "-whitespace/parens", "+runtime/indentation_namespace" ], "cpplint.extensions": [ "cpp", "h++", "cuh", "c", "c++", "cu", "hxx", "hpp", "cc", "cxx", "h" ], "cpplint.headers": ["h++", "cuh", "hxx", "hpp", "h"] // }uncrustify.cfgfile to your project if not presentCMAKE
settings.json{ // "cmakeFormat.args": [ "--line-width=80", "--tab-size=2", "--use-tabchars=false", "--command-case=lower", "--separate-fn-name-with-space=false", "--separate-ctrl-name-with-space=false", "--dangle-parens=false", "--max-prefix-chars=2", "--max-lines-hwrap=0", "--disable=autosort", "--enable-markup=true" ] // }Full VSCode Settings
{ // Global: format on save "editor.formatOnSave": true, // ─── Python ───────────────────────────────────────────────────────────── "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" }, "black-formatter.args": ["--line-length", "88"], "flake8.importStrategy": "fromEnvironment", "flake8.args": [ "--max-line-length=88", "--extend-ignore=E701,W503,E203", "--docstring-convention=pep257" ], // ─── JavaScript / Typescript / HTML / CSS / YAML ──────────────────────────────────────────── "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[javascriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[typescriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[html]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[css]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[yaml]": { "editor.defaultFormatter": "esbenp.prettier-vscode", "prettier.singleQuote": true }, "eslint.enable": true, "eslint.run": "onType", "eslint.validate": [ "javascript", "typescript", "javascriptreact", "typescriptreact", "html" ], "css.validate": false, "scss.validate": false, "less.validate": false, // ─── C++ ──────────────────────────────────────────────────────────────── "cpplint.cpplintPath": "/home/abdallah/.local/bin/cpplint", "cpplint.lineLength": 100, "cpplint.filters": [ "-build/include_subdir", "-whitespace/braces", "-build/namespaces", "-whitespace/indent", "-whitespace/indent_namespace", "-whitespace/parens", "+runtime/indentation_namespace" ], "cpplint.extensions": [ "cpp", "h++", "cuh", "c", "c++", "cu", "hxx", "hpp", "cc", "cxx", "h" ], "cpplint.headers": ["h++", "cuh", "hxx", "hpp", "h"], // ─── CMake ───────────────────────────────────────────────────────────── "cmakeFormat.args": [ "--line-width=80", "--tab-size=2", "--use-tabchars=false", "--command-case=lower", "--separate-fn-name-with-space=false", "--separate-ctrl-name-with-space=false", "--dangle-parens=false", "--max-prefix-chars=2", "--max-lines-hwrap=0", "--disable=autosort", "--enable-markup=true" ], // ─── XML ─────────────────────────────────────────────────────────────── "[xml]": { "editor.defaultFormatter": "redhat.vscode-xml" }, "xml.format.enabled": true, "xml.preferences.quoteStyle": "double", "xml.format.enforceQuoteStyle": "preferred", "xml.format.maxLineWidth": 80 }Beta Was this translation helpful? Give feedback.
All reactions