Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoBechtel committed Nov 12, 2023
0 parents commit 15990d0
Show file tree
Hide file tree
Showing 15 changed files with 729 additions and 0 deletions.
176 changes: 176 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store

1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"./prettier/index.mjs"
1 change: 1 addition & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "./semantic-release/index.cjs" }
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Style 🛼

> Roll in style.
Highly opinionated configuration files for typescript projects. Inspired by [@vercel/style-guide](https://github.com/vercel/style-guide)

## Usage

```bash
npm i -D @timobechtel/style prettier eslint typescript
```

### Prettier

```bash
echo '"@timobechtel/style/prettier/index.mjs"' > .prettierrc
```

### Typescript

```bash
echo '{ "extends": "@timobechtel/style/tsconfig/core" }' > tsconfig.json
```

### Eslint

```bash
echo 'const{resolve}=require("node:path");const project=resolve(process.cwd(),"tsconfig.json");module.exports={root:true,extends:[require.resolve("@timobechtel/style/eslint/core.cjs")],parserOptions:{project},settings:{"import/resolver":{typescript:{project}}}};' > .eslintrc.cjs
```

Or copy the following to a `.eslintrc.cjs` manually:

```js
const { resolve } = require('node:path');

const project = resolve(process.cwd(), 'tsconfig.json');

module.exports = {
root: true,
extends: [require.resolve('@timobechtel/style/eslint/core.cjs')],
parserOptions: {
project,
},
settings: {
'import/resolver': {
typescript: {
project,
},
},
},
};
```

### semantic-release

This repo also contains a [semantic-release](https://github.com/semantic-release/semantic-release) configuration.

```bash
npm i -D semantic-release
```

```bash
echo '{ "extends": "@timobechtel/style/semantic-release/index.cjs" }' > .releaserc.json
```
Binary file added bun.lockb
Binary file not shown.
49 changes: 49 additions & 0 deletions eslint/core.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// @ts-check
const { defineConfig } = require('eslint-define-config');

module.exports = defineConfig({
extends: [
'eslint:recommended',
'plugin:import/recommended',
'prettier',
require.resolve('./rules/base.cjs'),
require.resolve('./rules/import.cjs'),
require.resolve('./rules/unicorn.cjs'),
],
plugins: [],
env: {
es2021: true,
node: true,
browser: true,
},
// Report unused `eslint-disable` comments.
reportUnusedDisableDirectives: true,
// Tell ESLint not to ignore dot-files, which are ignored by default.
ignorePatterns: ['!.*.js'],
// Global settings used by all overrides.
settings: {
// Use the Node resolver by default.
'import/resolver': { node: {} },
},
// Global parser options.
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
},
overrides: [
{
files: ['*.ts?(x)'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/strict',
'plugin:@typescript-eslint/strict-type-checked',
'plugin:@typescript-eslint/stylistic',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:import/typescript',
'prettier',
require.resolve('./rules/typescript.cjs'),
],
},
],
});
82 changes: 82 additions & 0 deletions eslint/rules/base.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// @ts-check
const { defineConfig } = require('eslint-define-config');

module.exports = defineConfig({
rules: {
// prefer arrow functions for callbacks
'prefer-arrow-callback': [
'warn',
{
allowNamedFunctions: true,
allowUnboundThis: true,
},
],
// console logs other than error and warn are only needed for debugging, so they should be removed before merging
'no-console': [
'error',
{
allow: [
'warn',
'error',
'clear',
// sometimes we really need to log something, even in production, so info is allowed in edge cases
'info',
],
},
],
'max-depth': ['warn', 4],
// some globals, like "name" might be similar to the name of a variable, so we prevent them from being used
'no-restricted-globals': ['error', 'event', 'name'],
// Require curly braces for multiline blocks.
curly: ['warn', 'multi-line'],
// Require default clauses in switch statements to be last (if used).
'default-case-last': 'error',
// Require triple equals (`===` and `!==`).
eqeqeq: 'error',
// disallow the use of `alert()`
'no-alert': 'error',
// Disallow renaming import, export, and destructured assignments to the same name.
'no-useless-rename': 'warn',
// Require `let` or `const` instead of `var`.
'no-var': 'error',
// Require object literal shorthand syntax.
'object-shorthand': 'warn',
// Require default to `const` instead of `let`.
'prefer-const': 'warn',
// Require rest parameters instead of `arguments`.
'prefer-rest-params': 'error',
// Require spread syntax instead of `.apply()`.
'prefer-spread': 'error',
// Require template literals instead of string concatenation.
'prefer-template': 'warn',
// Disallow returning values from Promise executor functions.
'no-promise-executor-return': 'error',
// Disallow loops with a body that allows only one iteration.
'no-unreachable-loop': 'error',
// Require a capital letter for constructors.
'new-cap': ['error', { capIsNew: false }],
// Disallow the omission of parentheses when invoking a constructor with no arguments.
'new-parens': 'warn',
// Disallow if as the only statement in an else block.
'no-lonely-if': 'warn',
// Disallow ternary operators when simpler alternatives exist.
'no-unneeded-ternary': 'error',
// Require use of an object spread over Object.assign.
'prefer-object-spread': 'warn',
// Disallow labels that share a name with a variable.
'no-label-var': 'error',
// Disallow initializing variables to `undefined`.
'no-undef-init': 'warn',
// Disallow unused variables.
'no-unused-vars': [
'error',
{
args: 'after-used',
argsIgnorePattern: '^_',
ignoreRestSiblings: false,
vars: 'all',
varsIgnorePattern: '^_',
},
],
},
});
16 changes: 16 additions & 0 deletions eslint/rules/css-in-js.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-check
const { defineConfig } = require('eslint-define-config');

module.exports = defineConfig({
rules: {
'no-restricted-syntax': [
'error',
{
// catches common mistakes when writing comments in CSS
selector:
'TemplateElement[value.cooked=/\\s+\\u002F\\u002F\\s*/], Literal[value=/\\s+\\u002F\\u002F\\s*/]',
message: 'Invalid comment syntax. Use `/* */` instead of `//`.',
},
],
},
});
Loading

0 comments on commit 15990d0

Please sign in to comment.