Skip to content

Commit

Permalink
chore: add commitlint, eslint, prettier, lint-staged, husky and types…
Browse files Browse the repository at this point in the history
…cript
  • Loading branch information
alvarogfn committed Apr 12, 2024
1 parent 1126329 commit bafb510
Show file tree
Hide file tree
Showing 12 changed files with 4,236 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.vscode
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
53 changes: 53 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## PNPM related ###############
## https://pnpm.io/npmrc #
###############################

# Not always possible to be strict, but if it works for you, keep it to true.
# https://pnpm.io/next/npmrc#strict-peer-dependencies
strict-peer-dependencies=true

# https://pnpm.io/npmrc#auto-install-peers
auto-install-peers=true

# Helps locating duplicates, default in v8
# https://pnpm.io/next/npmrc#use-lockfile-v6
use-lockfile-v6=true

# Will fix duplicates due to peer-dependencies (>=7.29.0), default in v8
# https://github.com/pnpm/pnpm/releases/tag/v7.29.0
dedupe-peer-dependents=true

# Helps with peer-deps (>=7.23.0), default in v8
# https://pnpm.io/npmrc#resolve-peers-from-workspace-root
resolve-peers-from-workspace-root=true

# default to 'lowest' in v8.5.0
# set to highest for reasons specified here: https://github.com/pnpm/pnpm/issues/6463
# https://pnpm.io/npmrc#resolution-mode
resolution-mode=highest

# Default in 8.1.0 to fix issues with root/workspaces hoisting
# https://pnpm.io/npmrc#dedupe-direct-deps
dedupe-direct-deps=false

# Pinlock to exact version (default is '^')
# https://pnpm.io/npmrc#save-prefix
# see also how save-workspace-protocol affect this https://pnpm.io/npmrc#save-workspace-protocol
save-prefix=''

# Most of the time, you want to use the rolling protocol for monorepos
# https://pnpm.io/npmrc#save-workspace-protocol
save-workspace-protocol=rolling

# Specifies which exact Node.js version should be used for the project's runtime.
# pnpm will automatically install the specified version of Node.js and use it
# for running pnpm run commands or the pnpm node command.
# https://pnpm.io/npmrc#save-workspace-protocol
use-node-version=20.12.2

# Prevent contributors of your project from adding new incompatible dependencies
# This way, even if someone is using Node.js v16, they will not be able to install
# a new dependency that doesn't support Node.js v20.12.2.
# https://pnpm.io/npmrc#use-node-version
node-version=20.12.2
engine-strict=true
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"trailingComma": "es5",
"useTabs": false,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"jsxSingleQuote": false,
"arrowParens": "always",
"endOfLine": "lf",
"printWidth": 80
}
1 change: 0 additions & 1 deletion READMEE.md

This file was deleted.

8 changes: 8 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
extends: ['@commitlint/config-conventional'],
rules: {
'body-empty': [2, 'always'],
'footer-empty': [2, 'always'],
'scope-empty': [2, 'always'],
},
};
169 changes: 169 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { createRequire } from 'node:module';
import js from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';
import { defineFlatConfig } from 'eslint-define-config';
import tsEslint from 'typescript-eslint';
// import arrayFuncPlugin from 'eslint-plugin-array-func';
// import eslintCommentsPlugin from 'eslint-plugin-eslint-comments';
import importPlugin from 'eslint-plugin-import';
import perfectionistPlugin from 'eslint-plugin-perfectionist';
import unicornPlugin, { configs as unicornConfig } from 'eslint-plugin-unicorn';
// import promisePlugin from 'eslint-plugin-promise';
// import noSecretsPlugin from 'eslint-plugin-no-secrets';
// import regexpPlugin from 'eslint-plugin-regexp';
// import writeGoodCommentsPlugin from 'eslint-plugin-write-good-comments';
import onlyWarnPlugin from 'eslint-plugin-only-warn';
import vitestPlugin from 'eslint-plugin-vitest';
import globals from 'globals';

export default defineFlatConfig([
// global ignores
{
ignores: [
'node_modules',
'coverage',
'dist',
'pnpm-lock.yaml',
],
},

// override default eslint rules
{
...js.configs.recommended,
rules: {
'arrow-body-style': ['warn', 'as-needed'],
'class-methods-use-this': 'off',
'dot-notation': 'off',
'max-params': 'off',
'no-loop-func': 'off',
'no-loss-of-precision': 'off',
'no-magic-numbers': 'off',
'no-unused-vars': 'off',
},
},

{
files: ['**/*'],
languageOptions: {
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
},
plugins: {
import: importPlugin,
'only-warn': onlyWarnPlugin,
perfectionist: perfectionistPlugin,
unicorn: unicornPlugin,
},
rules: {
'import/consistent-type-specifier-style': ['warn', 'prefer-top-level'],
'import/default': 'warn',
'import/export': 'warn',
'import/namespace': 'warn',
'import/newline-after-import': 'warn',
'import/no-absolute-path': 'warn',
'import/no-duplicates': 'warn',
'import/no-extraneous-dependencies': 'warn',
'import/no-named-as-default': 'warn',
'import/no-named-as-default-member': 'warn',
'import/no-unused-modules': 'warn',
'import/order': 'warn',

'perfectionist/sort-array-includes': 'warn',
'perfectionist/sort-classes': 'warn',
'perfectionist/sort-enums': 'warn',
'perfectionist/sort-exports': 'warn',
'perfectionist/sort-interfaces': 'warn',
'perfectionist/sort-jsx-props': 'warn',
'perfectionist/sort-maps': 'warn',
'perfectionist/sort-named-exports': 'warn',
'perfectionist/sort-named-imports': 'warn',
'perfectionist/sort-object-types': 'warn',
'perfectionist/sort-objects': 'warn',
'perfectionist/sort-union-types': 'warn',

...unicornConfig.recommended.rules,
'unicorn/prevent-abbreviations': 'off',
},
settings: {
'import/parsers': {
espree: ['.js', '.cjs', '.mjs', '.jsx'],
},
'import/resolver': {
node: true,
typescript: true,
},
},
},

{
// https://typescript-eslint.io/
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: tsEslint.parser,
parserOptions: {
project: ['./tsconfig.json', './tsconfig.node.json'],
},
},
plugins: {
'@typescript-eslint': tsEslint.plugin,
},
rules: {
'@typescript-eslint/await-thenable': 'warn',
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/ban-types': 'warn',
'@typescript-eslint/no-array-constructor': 'warn',
'@typescript-eslint/no-base-to-string': 'warn',
'@typescript-eslint/no-duplicate-enum-values': 'warn',
'@typescript-eslint/no-duplicate-type-constituents': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-extra-non-null-assertion': 'warn',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-for-in-array': 'warn',
'@typescript-eslint/no-implied-eval': 'warn',
'@typescript-eslint/no-loss-of-precision': 'warn',
'@typescript-eslint/no-misused-new': 'warn',
'@typescript-eslint/no-misused-promises': 'warn',
'@typescript-eslint/no-namespace': 'warn',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'warn',
'@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/no-this-alias': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unnecessary-type-constraint': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-var-requires': 'warn',
'@typescript-eslint/prefer-as-const': 'warn',
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/restrict-plus-operands': 'warn',
'@typescript-eslint/restrict-template-expressions': 'warn',
'@typescript-eslint/triple-slash-reference': 'warn',
'@typescript-eslint/unbound-method': 'warn',
},
},

// testing with vitest
{
files: ['**/*.spec.ts', '**/*.spec.tsx'],
languageOptions: {
globals: {
...globals.jest,
},
},
plugins: {
vitest: vitestPlugin,
},
rules: {
'vitest/expect-expect': 'warn',
'vitest/no-commented-out-tests': 'warn',
'vitest/no-identical-title': 'warn',
'vitest/no-import-node-test': 'warn',
'vitest/require-local-test-context-for-concurrent-snapshots': 'warn',
'vitest/valid-describe-callback': 'warn',
'vitest/valid-expect': 'warn',
'vitest/valid-title': 'warn',
},
},

eslintConfigPrettier,
]);
53 changes: 53 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@octopost/backend",
"version": "1.0.0",
"main": "index.ts",
"type": "module",
"engines": {
"node": "20",
"pnpm": "8"
},
"scripts": {
"dev": "tsx --watch src/index.ts",
"build": "tsx src/index.ts",
"lint": "eslint . --max-warnings=0 --no-warn-ignored",
"prepare": "husky"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@commitlint/cli": "19.2.1",
"@commitlint/config-conventional": "19.1.0",
"@commitlint/cz-commitlint": "19.2.0",
"@eslint/js": "9.0.0",
"commitizen": "4.3.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-define-config": "2.1.0",
"eslint-plugin-array-func": "5.0.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-only-warn": "1.1.0",
"eslint-plugin-perfectionist": "2.8.0",
"eslint-plugin-unicorn": "52.0.0",
"eslint-plugin-vitest": "0.5.1",
"globals": "15.0.0",
"husky": "9.0.11",
"lint-staged": "15.2.2",
"prettier": "3.2.5",
"tsx": "4.7.2",
"typescript": "5.4.5",
"typescript-eslint": "7.6.0"
},
"config": {
"commitizen": {
"path": "@commitlint/cz-commitlint"
}
},
"lint-staged": {
"*.{ts,tsx}": [
"eslint --fix --report-unused-disable-directives --max-warnings=0 --no-warn-ignored",
"prettier --write --ignore-unknown"
]
}
}
Loading

0 comments on commit bafb510

Please sign in to comment.