Skip to content

Instantly share code, notes, and snippets.

@tiagofrancafernandes
Last active September 19, 2024 17:52
Show Gist options
  • Save tiagofrancafernandes/12e4fc40d9e00cf4c329fdd220467a76 to your computer and use it in GitHub Desktop.
Save tiagofrancafernandes/12e4fc40d9e00cf4c329fdd220467a76 to your computer and use it in GitHub Desktop.
dev-prettier Snippets

Prettier config mode

  • A "prettier" key in your package.json file.
  • A .prettierrc file written in JSON or YAML.
  • A .prettierrc.json, .prettierrc.yml, .prettierrc.yaml, or .prettierrc.json5 file.
  • A .prettierrc.js, or prettier.config.js file that exports an object using export default or module.exports (depends on the type value in your package.json).
  • A .prettierrc.mjs, or prettier.config.mjs file that exports an object using export default.
  • A .prettierrc.cjs, or prettier.config.cjs file that exports an object using module.exports.
  • A .prettierrc.toml file.

Examples

VSCode Settings:

{
    // ~/.config/Code/User/settings.json or .vscode/settings.json
    // Extension ID: esbenp.prettier-vscode
    // ...
    "prettier.trailingComma": "es5",
    "prettier.tabWidth": 4,
    "prettier.useTabs": false,
    "prettier.semi": true,
    "prettier.singleQuote": true,
    "prettier.endOfLine": "lf",
    // ...
}

JSON:

{
  "trailingComma": "es5",
  "tabWidth": 4,
  "semi": false,
  "singleQuote": true
}

JS:

// prettier.config.js or .prettierrc.js
module.exports = {
  trailingComma: "es5",
  tabWidth: 4,
  semi: false,
  singleQuote: true,
};

JS as module:

// .prettierrc.mjs or change "type" to "module" in package.json
const config = {
    trailingComma: "es5",
    tabWidth: 4,
    useTabs: false,
    semi: true,
    singleQuote: true,
    endOfLine: "lf",
}

export default config;

YAML:

# .prettierrc or .prettierrc.yaml
trailingComma: "es5"
tabWidth: 4
semi: false
singleQuote: true

TOML:

# .prettierrc.toml
trailingComma = "es5"
tabWidth = 4
semi = false
singleQuote = true
// .prettierrc.mjs
const config = {
    "tabWidth": 4,
    "useTabs": false,
    "semi": true,
    "singleQuote": true,
    "trailingComma": "none",
    "arrowParens": "avoid",
    "endOfLine": "lf",
    "trimTrailingWhitespace": true,
    "stripWhitespace": true,
    "vueIndentScriptAndStyle": false, // Se deve dar espaço ao inicio das tags script e stype (vue)
    "htmlWhitespaceSensitivity": "ignore",
    "printWidth": 140,
    "bracketSpacing": true
}

export default config;
// .prettierrc
{
    "tabWidth": 4,
    "useTabs": false,
    "semi": true,
    "singleQuote": true,
    "trailingComma": "es5",
    "arrowParens": "avoid",
    "endOfLine": "lf",
    "trimTrailingWhitespace": true,
    "stripWhitespace": true,
    "vueIndentScriptAndStyle": false,
    "htmlWhitespaceSensitivity": "ignore",
    "singleAttributePerLine": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment