diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1718460 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,27 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{js,jsx,ts,tsx}] +indent_style = space +indent_size = 4 + +[*.{json}] +indent_style = space +indent_size = 4 + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +[*.md] +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab + diff --git a/README.md b/README.md index a047e81..82c0546 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,63 @@ This project: * Provides an `eslint-config-scality` package that can be added as a dependency in other projects. That way, coding style can automatically be checked using eslint. + +## Prettier baseline + +This repository also provides a **baseline Prettier configuration** for Scality +object repositories: 4-space JavaScript/TypeScript indentation, 120-character +line length, single quotes, semicolons, trailing commas, and +`quoteProps: 'as-needed'`. + +The configuration lives in `prettier.config.cjs`. + +To use it in a project: + +1. Install Prettier in the project: + + ```sh + yarn add --dev prettier + # or + npm install --save-dev prettier + ``` + +2. Copy or extend the configuration: + + ```js + // prettier.config.cjs + module.exports = require('eslint-config-scality/prettier.config.cjs'); + ``` + +3. Add convenience scripts: + + ```json + { + "scripts": { + "format": "prettier --write .", + "format:check": "prettier --check ." + } + } + ``` + +Projects are free to override options locally (for example `tabWidth` or +`printWidth`) if they have strong legacy constraints, but this configuration +is intended to be the **default Scality baseline** for new or reformatted +Node.js codebases. YAML defaults to 2-space indentation, JSON and Markdown to +4-space indentation, and Markdown prose is left un-reflowed by default +(`proseWrap: 'preserve'`) to avoid noisy diffs in existing documentation. + +## Editor configuration + +For a consistent editor experience, you can copy or adapt the `.editorconfig` +from this repository. It aligns with the ESLint and Prettier baselines: + +- **JS/TS**: spaces with 4-space indentation. +- **JSON/Markdown**: spaces with 4-space indentation. +- **YAML**: spaces with 2-space indentation. +- `end_of_line = lf`, `insert_final_newline = true`, + `trim_trailing_whitespace = true`. + +## Contributing + +- See `CONTRIBUTING.md` for contribution guidelines and coding standards. +- See `TESTING.md` for details on running the linters and tests in this repo. diff --git a/prettier.config.cjs b/prettier.config.cjs new file mode 100644 index 0000000..bcf3695 --- /dev/null +++ b/prettier.config.cjs @@ -0,0 +1,26 @@ +module.exports = { + tabWidth: 4, + useTabs: false, + printWidth: 120, + singleQuote: true, + quoteProps: 'as-needed', + semi: true, + trailingComma: 'all', + arrowParens: 'avoid', + bracketSpacing: true, + endOfLine: 'lf', + overrides: [ + { + files: ['*.yml', '*.yaml'], + options: { + tabWidth: 2, + }, + }, + { + files: ['*.md'], + options: { + proseWrap: 'preserve', + }, + }, + ], +};