Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(presets): add multiline #4

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,23 @@ const defaultTypescriptRules = {
selector: 'variable',
types: ['boolean'],
format: ['PascalCase'],
prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
prefix: [
'is',
'should',
'has',
'can',
'did',
'will',
],
},

{
// Enforce that all variables are either in camelCase or UPPER_CASE
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
format: [
'camelCase',
'UPPER_CASE',
],
},
{
// Ignore destructured names
Expand Down Expand Up @@ -126,11 +136,21 @@ const defaultTypescriptRules = {
module.exports = {
root: true,

ignorePatterns: ['node_modules', 'build', 'dist', '!.*', 'examples'],
ignorePatterns: [
'node_modules',
'build',
'dist',
'!.*',
'examples',
],

overrides: [
{
files: ['*.js', '*.mjs', '*.cjs'],
files: [
'*.js',
'*.mjs',
'*.cjs',
],
parserOptions: {
ecmaVersion: 'latest',
},
Expand All @@ -151,20 +171,33 @@ module.exports = {
rules: {
...defaultRules,
// Helps import the correct file extension
'import/extensions': ['error', 'always', { ignorePackages: true }],
'import/extensions': [
'error',
'always',
{ ignorePackages: true },
],
'node/no-unsupported-features/es-syntax': ['off'],
},
},
{
files: ['*.ts', '*.mts', '*.cts', '*.tsx'],
files: [
'*.ts',
'*.mts',
'*.cts',
'*.tsx',
],
extends: [
'eslint:recommended',
'plugin:unicorn/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'prettier',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'import', 'unicorn'],
plugins: [
'@typescript-eslint',
'import',
'unicorn',
],
parserOptions: {
EXPERIMENTAL_useProjectService: true,
// project: true,
Expand Down
10 changes: 8 additions & 2 deletions .lintstagedrc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ const prettierCmd = 'prettier --ignore-unknown --write';

export default {
// Javascript sources
'*.{js,cjs,mjs}': [eslintCmd, prettierCmd],
'*.{js,cjs,mjs}': [
eslintCmd,
prettierCmd,
],

// Typescript sources
'*.{ts,cts,mts}': [eslintCmd, prettierCmd],
'*.{ts,cts,mts}': [
eslintCmd,
prettierCmd,
],

// Other files
'*!(.{js,cjs,mjs,ts,cts,mts})': [prettierCmd],
Expand Down
12 changes: 9 additions & 3 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
"printWidth": 120,
"endOfLine": "lf",
"organizeImportsSkipDestructiveCodeActions": true,
"multilineArraysWrapThreshold": 1,
"plugins": [
"prettier-plugin-pkg",
"prettier-plugin-organize-imports",
"prettier-plugin-sh"
"prettier-plugin-sh",
"prettier-plugin-multiline-arrays"
],
"overrides": [
{
"files": ["*.sh"],
"files": [
"*.sh"
],
"options": {
"indent": 4,
"tabWidth": 4
}
},
{
"files": [".prettierrc.json"],
"files": [
".prettierrc.json"
],
"options": {
"printWidth": 80
}
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Depending on how are you creating your own config file, you may choose to instal

- `devDependencies` (`-D`, `--save-dev`).
- `peerDependencies` (`--save-peer`).
- `dependecies`.
- `dependencies`.

<!-- TODO: Add documentation about other types of installation -->

Expand Down Expand Up @@ -90,6 +90,18 @@ Compatibility with Shell Script for Bash or sh.
npm add -D prettier-plugin-sh
```

### Multiline preset (`sh`)

Multiline elements for some languages.

#### Required plugins:

- [prettier-plugin-multiline-arrays](https://github.com/electrovir/prettier-plugin-multiline-arrays)

```sh
npm add -D prettier-plugin-multiline-arrays
```

## Usage

### Simple usage
Expand Down Expand Up @@ -150,7 +162,11 @@ import {
getMergedOverrideFor,
} from '@elegantech/prettier-multi-config/presets';

const selectedPresets = ['base', 'php', 'sh'];
const selectedPresets = [
'base',
'php',
'sh',
];

/** @type {import("prettier").Config} */
const config = {
Expand Down
6 changes: 5 additions & 1 deletion examples/shareable-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {

import { Config } from 'prettier';

const selectedPresets: PresetName[] = ['base', 'php', 'sh'];
const selectedPresets: PresetName[] = [
'base',
'php',
'sh',
];

const config: Config = {
// Add global configurations for selected presets
Expand Down
13 changes: 11 additions & 2 deletions internal/configs/prettierrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ import { getMergedGlobalOptionsFor, getMergedOverrideFor, getPluginsFor } from '
* The default config to be used as default.
*/
const config: Config = {
...getMergedGlobalOptionsFor(['base', 'sh']),
...getMergedGlobalOptionsFor([
'base',
'multiline',
'sh',
]),

plugins: getPluginsFor(['base', 'sh']),
plugins: getPluginsFor([
'base',
'sh',
'multiline',
]),

overrides: [
//
...getMergedOverrideFor('base'),
...getMergedOverrideFor('multiline'),
...getMergedOverrideFor('sh'),
{
files: ['.prettierrc.json'],
Expand Down
5 changes: 4 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"target": "ESNext",
"strict": true
},
"exclude": ["node_modules", "**/node_modules/*"]
"exclude": [
"node_modules",
"**/node_modules/*"
]
}
Loading