Skip to content

Commit

Permalink
feat(stylelint-config): Implement Stylelint Common Rule set (#364)
Browse files Browse the repository at this point in the history
* feat(stylelint-config): Implement Stylelint Common Rule set

* update keywords

* update readme

* add release.config

* update readme

* update snapshot
  • Loading branch information
wakamsha authored Feb 12, 2025
1 parent 87beb0c commit 3ceb96f
Show file tree
Hide file tree
Showing 20 changed files with 4,703 additions and 63 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"packageManager": "pnpm@9.15.1",
"scripts": {
"format": "prettier -c './**/*.@(js|cjs|ts|tsx|md)' -w",
"eslint-config": "pnpm -F 'eslint-config-moneyforward'"
"eslint-config": " pnpm -F 'eslint-config-moneyforward'",
"stylelint-config": "pnpm -F '@moneyforward/stylelint-config'"
},
"repository": {
"type": "git",
Expand Down
85 changes: 85 additions & 0 deletions packages/stylelint-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# @moneyforward/stylelint-config

The Stylelint rules of Money Forward, Inc as an extensible shared config.

## Usage

### 1. Install dependencies (and peer dependencies)

```bash
npm install --save-dev stylelint @moneyforward/stylelint-config
```

### 2. Configure Stylelint

Within your Stylelint config file (`stylelint.config.js` or `.stylelintrc.js`):

```js
export default {
extends: ['@moneyforward/stylelint-config/essentials'],
};
```

If you need CSS Modules support:

```diff
export default {
- extends: ['@moneyforward/stylelint-config/essentials'],
+ extends: ['@moneyforward/stylelint-config/essentials', '@moneyforward/stylelint-config/css-modules'],
};
```

Must be added after `essentials`.

We also provide various other rule sets that you can configure to suit your project.

```json
{
"extends": [
"@moneyforward/stylelint-config/essentials",
"@moneyforward/stylelint-config/css-modules",
"@moneyforward/stylelint-config/scss"
]
}
```

| Rule set | Summary | Dependencies |
| ------------: | :------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `essentials` | Contains standard, and recess-order configs | [`standard`](https://github.com/stylelint/stylelint-config-standard) <br> [`recess-order`](https://github.com/stormwarning/stylelint-config-recess-order) |
| `css-modules` | Contains [CSS Modules](https://github.com/css-modules/css-modules) config | - |
| `scss` | Contains SCSS config | [`scss`](https://github.com/stylelint-scss/stylelint-config-standard-scss) |

Must be added after `essentials`.

We also provide various other rule sets that you can configure to suit your project.

If the value of a rule does not suit you, specify that rule in the "rules" section with the value you want:

```diff
export default {
extends: ['@moneyforward/stylelint-config/essentials'],
+ rules: {
+ value-keyword-case': null,
+ },
};
```

## Migrate from an existing configuration

@moneyforward/stylelint-config contains various plugins related to different rule sets. Therefore, users don't need to install them separately. If you have installed them in your existing configuration, we recommend uninstalling them.

```bash
npm uninstall stylelint-config-standard \
stylelint-config-recess-order \
stylelint-config-standard-scss \
```

## Versioning

- Increment major version: Changed **error** rules.
- Increment minor version: Changed **warn** rules.
- Increment patch version: Not changed **error** and **warn** rules.

## License

Open source [licensed as MIT](https://github.com/moneyforward/dummy).
30 changes: 30 additions & 0 deletions packages/stylelint-config/configs/css-modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default {
rules: {
// https://stylelint.io/user-guide/rules/function-no-unknown/
'function-no-unknown': [
true,
{
// cf. https://github.com/css-modules/css-modules/blob/master/docs/composition.md#exceptions
ignoreFunctions: ['global'],
},
],

// https://stylelint.io/user-guide/rules/property-no-unknown/
'property-no-unknown': [
true,
{
// cf. https://github.com/css-modules/css-modules/blob/master/docs/composition.md
ignoreProperties: ['composes'],
},
],

// https://stylelint.io/user-guide/rules/selector-pseudo-class-no-unknown/
'selector-pseudo-class-no-unknown': [
true,
{
// cf. https://github.com/css-modules/css-modules/blob/master/docs/composition.md#exceptions
ignorePseudoClasses: ['global', 'local'],
},
],
},
};
14 changes: 14 additions & 0 deletions packages/stylelint-config/configs/essentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
extends: ['stylelint-config-standard', 'stylelint-config-recess-order'],

rules: {
// https://stylelint.io/user-guide/rules/declaration-block-no-redundant-longhand-properties/
'declaration-block-no-redundant-longhand-properties': [
true,
{
// Exclude `grid-template` to be able to use `grid-template-areas`.
ignoreShorthands: ['grid-template'],
},
],
},
};
3 changes: 3 additions & 0 deletions packages/stylelint-config/configs/scss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
extends: ["stylelint-config-standard-scss"],
};
26 changes: 26 additions & 0 deletions packages/stylelint-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { essentials, node, typescript } from 'eslint-config-moneyforward/flat';

export default [
{
files: ['**/*.js'],
},

...essentials,
{
rules: {
'import/no-default-export': ['off'],
'unicorn/filename-case': ['off'],
},
},
{
files: ['**/*.config.@(js|ts)'],
rules: {
'no-restricted-exports': ['off'],
'import/no-extraneous-dependencies': ['off'],
},
},

...node,

...typescript,
];
55 changes: 55 additions & 0 deletions packages/stylelint-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@moneyforward/stylelint-config",
"version": "0.1.0",
"description": "Money Forward's Stylelint rules as an extensible shared config.",
"type": "module",
"exports": {
"./*": "./configs/*"
},
"engines": {
"node": ">=18.12.0"
},
"files": [
"configs"
],
"scripts": {
"lint": "eslint './**/*.@(js|ts)'",
"test": "vitest",
"release": "semantic-release"
},
"repository": {
"type": "git",
"url": "https://github.com/moneyforward/frontend-tools.git",
"directory": "packages/stylelint-config"
},
"keywords": [
"stylelint",
"stylelint-config",
"style best practices",
"css modules",
"scss"
],
"author": "Money Forward Engineers",
"license": "MIT",
"bugs": {
"url": "https://github.com/moneyforward/frontend-tools/issues"
},
"homepage": "https://github.com/moneyforward/frontend-tools/tree/main/packages/stylelint-config#readme",
"dependencies": {
"stylelint-config-recess-order": "^6.0.0",
"stylelint-config-standard": "^37.0.0",
"stylelint-config-standard-scss": "^14.0.0"
},
"devDependencies": {
"@frontend-tools/release-config": "workspace:*",
"@types/node": "22.10.2",
"eslint": "9.20.0",
"eslint-config-moneyforward": "workspace:*",
"stylelint": "16.13.0",
"typescript": "5.7.3",
"vitest": "3.0.5"
},
"peerDependencies": {
"stylelint": "^16.13.0"
}
}
1 change: 1 addition & 0 deletions packages/stylelint-config/release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@frontend-tools/release-config';
Loading

0 comments on commit 3ceb96f

Please sign in to comment.