Skip to content

Commit

Permalink
chore: add stylelint and prettier configurations, and create linting …
Browse files Browse the repository at this point in the history
…script
  • Loading branch information
lgersman committed Nov 13, 2024
1 parent 4162513 commit 4840c10
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 24 deletions.
41 changes: 41 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*#
# default prettier configuration
#
# this file is usually referenced in your own top level .prettierrc.js.
#
# ```
# const settings = require('@pnpmkambrium/core/presets/default/.prettierrc.js');
# module.exports = {
# ...settings,
# };
# ```
#
# You can remove it in case you don't use prettier
#*/
module.exports = {
semi: true,
tabWidth: 2,
singleQuote: true,
printWidth: 120,
trailingComma: 'all',
overrides: [
/*
# {
# "files": ["*.json5"],
# "options": { "singleQuote": false, "quoteProps": "preserve" },
# },
*/
{ files: ['*.yml'], options: { singleQuote: false } },
{
files: ['*.php'],
options: {
// see https://github.com/prettier/plugin-php?tab=readme-ov-file#visual-studio-code
// 8.3 is currently not supported by the plugin
phpVersion: '8.2',
braceStyle: '1tbs',
parser: 'php',
},
},
],
plugins: ['@prettier/plugin-php'],
};
11 changes: 11 additions & 0 deletions .stylelintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# default stylelint configuration
#
# this file is usually referenced in your own top level .stylelintrc.yaml.
#

extends:
- stylelint-config-recommended-scss
rules:
color-named: null
selector-class-pattern: null
70 changes: 70 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import prettier from 'eslint-plugin-prettier';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import _import from 'eslint-plugin-import';
import { fixupPluginRules, includeIgnoreFile } from '@eslint/compat';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

const gitignorePath = path.resolve(__dirname, '.gitignore');

export default [
includeIgnoreFile(gitignorePath),
{
ignores: ['**/*.md', 'packages/docs/**/*.min.js', '**/*.json', '**/*.code-workspace'],
},
...compat.extends('prettier'),
{
plugins: {
prettier,
react,
'react-hooks': fixupPluginRules(reactHooks),
'simple-import-sort': simpleImportSort,
import: fixupPluginRules(_import),
},

languageOptions: {
globals: {
...globals['shared-node-browser'],
...globals.browser,
...globals.node,
},

ecmaVersion: 'latest',
sourceType: 'module',

parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},

settings: {
react: {
version: 'detect',
},
},

rules: {
'prettier/prettier': [0],
'react-hooks/rules-of-hooks': ['error'],
'react-hooks/exhaustive-deps': ['warn'],
'react/prop-types': ['warn'],
'import/no-unresolved': ['warn'],
'no-console': ['warn'],
},
},
];
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"clean": "./scripts/clean.sh",
"distclean": "./scripts/distclean.sh",
"changeset": "./scripts/changeset.sh",
"lint": "./scripts/lint.sh",
"update-dependencies": "./scripts/update-dependencies.sh",
"storybook:start": "./scripts/storybook.sh dev -p 6006",
"storybook:build": "./scripts/storybook.sh build -o ./build/storybook-static",
Expand Down Expand Up @@ -43,7 +44,7 @@
"@commitlint/config-conventional": "19.5.0",
"@devcontainers/cli": "^0.72.0",
"@playwright/experimental-ct-react": "^1.48.2",
"@playwright/browser-chromium" : "^1.48.2",
"@playwright/browser-chromium": "^1.48.2",
"@prettier/plugin-php": "^0.22.2",
"@storybook/addon-essentials": "^8.4.2",
"@storybook/addon-interactions": "^8.4.2",
Expand All @@ -65,6 +66,10 @@
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "5.0.0",
"eslint-plugin-simple-import-sort": "12.1.1",
"@eslint/compat": "1.2.2",
"globals": "15.12.0",
"@eslint/js": "9.14.0",
"@eslint/eslintrc": "3.1.0",
"eslint-plugin-storybook": "^0.11.0",
"git-cz": "4.9.0",
"nano-staged": "0.8.0",
Expand All @@ -73,8 +78,7 @@
"react-dom": "18.3.1",
"storybook": "^8.4.2",
"stylelint": "^16.10.0",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-recommended-scss": "^14.1.0",
"stylelint-scss": "^6.8.1"
"stylelint-scss": "^6.9.0"
}
}
64 changes: 43 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

#
# script is not intended to be executed directly. use `pnpm exec ...` instead or call it as package script.
#
# this script is used to lint the codebase
#

# bootstrap the environment
source "$(realpath $0 | xargs dirname)/includes/bootstrap.sh"

# prettier lint
pnpm exec prettier --config ./.prettierrc.js --ignore-path ./.gitignore --check --ignore-unknown --log-level log . ||:

# # eslint lint
# # @TODO: convert config to new eslint 10 flat config
pnpm exec eslint --config ./eslint.config.mjs --no-error-on-unmatched-pattern .

# # stylelint lint
pnpm exec stylelint --config ./.stylelintrc.yml --ignore-path ./.gitignore --allow-empty-input **/*.{css,scss}

38 changes: 38 additions & 0 deletions scripts/wp-env-after-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,44 @@ EOF
# generate settings.json
cat << EOF > '.vscode/settings.json'
{
// show workspace folder in editor tab label
"workbench.editor.labelFormat": "short",
// see https://github.com/prettier/plugin-php?tab=readme-ov-file#visual-studio-code
"prettier.documentSelectors": ["**/*.{js,jsx,ts,tsx,json,md,yaml,yml,php}"],
"prettier.useEditorConfig": true,
"prettier.configPath": ".prettierrc.js",
"prettier.ignorePath": ".gitignore",
"prettier.enableDebugLogs": true,
"eslint.lintTask.enable": true,
"cSpell.useGitignore": true,
"editorconfig.generateAuto": false,
"editor.codeActionsOnSave": {
"source.fixAll": "never",
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
"stylelint.validate": ["css", "scss"],
"stylelint.packageManager": "pnpm",
"stylelint.config": {
"configBasedir": "\${workspaceFolder}"
},
"eslint.codeAction.showDocumentation": {
"enable": true
},
"[php]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "stylelint.vscode-stylelint"
},
"[scss]": {
"editor.defaultFormatter": "stylelint.vscode-stylelint"
},
"eslint.validate": ["javascript", "javascriptreact", "json", "jsonc", "json5"],
// enable globally (here: format on save)
"editor.formatOnSave": true,
// THIS FILE IS MACHINE GENERATED by .wp-env-afterStart.sh - DO NOT EDIT!
// If you need to confgure additional launch configurations consider defining them in a vscode *.code-workspace file
"intelephense.files.exclude": [
Expand Down

0 comments on commit 4840c10

Please sign in to comment.