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

Add prettier for linting #14

Closed
wants to merge 3 commits into from

Conversation

SeanAverS
Copy link

Fixes #8

Changes

  • install Prettier dependencies in package-lock.json and package.json

  • create .prettierrc file for Prettier settings

  • create .prettierignore file to ignore specific files

@LucasMatuszewski
Copy link
Contributor

Hey, looks good to me.

I have only 2 general suggestions, for consideration for everybody @vipyne @hyypeman

  1. I like to explicitly set all configs, even if we use the defaults, because:
  • it makes it clear that this is our decision, not an accident.
  • if somebody has local user settings different than default our workspace settings will overwrite them.
  • It's good to discuss all styling preferences upfront to avoid future discussions and just have the same style.
  1. I also like to use a library for sorting imports - otherwise it gets messy and everybody adds imports in a different order or just use auto-import. I use @trivago/prettier-plugin-sort-imports for this. We can customize the order of imports by folders or custom paths/aliases set in tsconfig.json as paths.

Below is my example prettier.config.cjs (the cjs file can have additional types, but we can easily refactor it to json if you prefer to stick with .prettierrc file):

/** @type {import("prettier").Config} */

/**
 * Options for Prettier.
 *
 * @see https://prettier.io/docs/en/options.html
 */
module.exports = {
  endOfLine: 'lf',
  singleQuote: true,
  trailingComma: 'es5',
  semi: true,
  printWidth: 100,
  tabWidth: 2,
  useTabs: false,
  arrowParens: 'avoid',
  bracketSpacing: true,
  bracketSameLine: false,
  jsxSingleQuote: false,
  plugins: [
    '@trivago/prettier-plugin-sort-imports',
  ],
  overrides: [
    {
      files: ['tsconfig.json', 'jsconfig.json'],
      options: {
        parser: 'jsonc',
      },
    },
  ],
  importOrderSeparation: true,
  importOrder: [
    '<THIRD_PARTY_MODULES>',
    '^@/app/(.*)$',
    '^@/collections/(.*)$',
    '^@/access/(.*)$',
    '^@/store/(.*)$',
    '^@/utils/(.*)$',
    '^@/payload-types$',
    '^@/payload-config$',
    '^@/lib/(.*)$',
    '^@/hooks/(.*)$',
    '^@/providers/(.*)$',
    '^@/fields/(.*)$',
    '^@/blocks/(.*)$',
    '^@/globals/(.*)$',
    '^@/components/(.*)$',
    '^@/cssVariables$',
    '^[./]',
  ],
  importOrderSortSpecifiers: true,
};

These paths are from by PayloadCMS project, but we would have to customize them to Housecat.

    "paths": {
      "@payload-config": [
        "./src/payload.config.ts"
      ],
      "react": [
        "./node_modules/@types/react"
      ],
      "@/access/*": [
        "./src/collections/Users/access/*"
      ],
      "@/collections/*": [
        "./src/collections/*"
      ],
      "@/components/*": [
        "./src/components/*"
      ],
      "@/fields/*": [
        "./src/fields/*"
      ],
      "@/hooks/*": [
        "./src/hooks/*"
      ],
      "@/globals/*": [
        "./src/globals/*"
      ],
      "@/utils/*": [
        "./src/utils/*"
      ],
      "@/blocks/*": [
        "./src/blocks/*"
      ],
      "@/providers/*": [
        "./src/providers/*"
      ],
      "@/payload-types": [
        "./src/payload-types"
      ],
      "@/cssVariables": [
        "./src/cssVariables"
      ]
    }

@hyypeman
Copy link
Collaborator

@SeanAverS thank you for the contribution. There seems to be some conflicts, have you pulled in the latest changes? @LucasMatuszewski I'm okay with explicit configs, it really doesn't matter too much as long as we all use the same thing

@SeanAverS SeanAverS closed this by deleting the head repository Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add prettier for linting
3 participants