0.6.0 โ€ข Published 3 months ago

personal-style-guide v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

SemVer Status Build Status

๐Ÿ’ก Motivation

Consistency in code style is key to maintaining scalable and maintainable projects. While many tools like ESLint, Prettier, and Stylelint exist, configuring them repeatedly across projects can be tedious and error-prone. This package centralizes the configuration for these tools, saving time and ensuring a unified development experience across all Didor projects.

This style guide also promotes best practices.

๐Ÿš€Getting Started

Prerequisites

ESLint, Prettier, Stylelint, Typescript are a peer dependency, so you need to install at the root of your project:

npm install --save-dev eslint prettier stylelint typescript

Installation

To install the package, run:

npm install --save-dev personal-style-guide

ESLint

Plugins Integrated

How to Use

You need to extend one or both of the following configurations.

  • personal-style-guide/eslint/browser for browser projects.
  • personal-style-guide/eslint/node for Node projects.

Create or update eslint.config.js in your project root and extend the configurations you need:

import eslintNode from "personal-style-guide/eslint/node";

export default [...eslintNode];

Prettier

How to Use

To use the shared Prettier config, create or update .prettierrc.config.js in your project root:

export { default } from "personal-style-guide/prettier/index.js";

If you need to extend the configuration, you can do so:

import prettierConfig from "personal-style-guide/prettier/index.js";

export default {
  ...prettierConfig,
  ...
};

Why We Don't Use Prettier with ESLint or Stylelint

To improve IDE performance and avoid redundant processing, we separate the responsibilities of Prettier and linters (ESLint/Stylelint):

  • ESLint and Stylelint: Focus only on code validation and enforcing rules.
  • Prettier: Handles code formatting exclusively.

By not integrating Prettier directly into ESLint or Stylelint:

  1. Faster IDE Performance: Linters donโ€™t need to process formatting errors, reducing overhead.
  2. Avoid Duplicated Tasks: Prevent running the file through both a linter and Prettier simultaneously.

Stylelint

Plugins Integrated

How to Use

Create or update stylelint.config.js in your project root:

module.exports = {
  extends: ["personal-style-guide/stylelint"],
};

TypeScript

How to Use

This style guide provides multiple TypeScript configs. These configurations are based on the environment you are working on, so you need to extend one of the following configurations:

  • personal-style-guide/typescript/node.
  • personal-style-guide/typescript/browser.

Ensure you have a tsconfig.json in your project root. You can extend the provided configuration if necessary:

{
  "extends": "personal-style-guide/typescript/node"
}

Markdown

โš ๏ธ Note: This configuration is designed for markdownlint. Install the Markdownlint extension in your editor (e.g., VS Code) for optimal use.

How to Use

To lint Markdown files, extend the provided configuration by creating or updating a .markdownlint.json file in your project root:

{
  "extends": "personal-style-guide/markdown"
}


## ๐Ÿ“‘ Scripts

Add the following scripts to your `package.json` to lint and format your code:

```json
{
  "scripts": {
    "lint:js": "eslint 'src/**/*.{js,ts,vue}'",
    "lint:css": "stylelint 'src/**/*.{scss,css}'",
    "format": "prettier --write 'src/**/*.{js,ts,vue,scss,css}'"
  }
}

๐Ÿ”„ Updating

To check for outdated dependencies, run:

npx npm-check-updates

This lists all outdated dependencies. It's important to read the release notes for each dependency to understand the changes.

Update dependencies running the interactive mode. It's recommended to update them one by one to avoid breaking changes.:

npx npm-check-updates --interactive

๐Ÿ—บ๏ธ Roadmap

  • Add configurations for testing frameworks (e.g., Jest, Vitest).
  • Add configurations for Vue and Nuxt projects.
  • Improve the ESLint configuration to group by file type.
  • Add @eslint/json and @eslint/markdown configurations to the ESLint setup.

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/my-feature).
  3. Make your changes and write tests.
  4. Commit your changes using a conventional commit message.
  5. Push your branch and open a Pull Request.

๐Ÿ“œ License

This template is licensed under the MIT License, which allows you to use, modify, and distribute the code freely, as long as the original license is included.

For more details, see the LICENSE file included in this repository.

๐ŸŒŸ Star Support

Your โญ๏ธ helps others discover this template and motivates continued development and improvements.

Special thanks to the open-source community for inspiring and supporting this template.