Skip to content

linz/style-js

Repository files navigation

@linzjs/style

Build Status License

NPM configuration for base typescript projects

Includes:

  • oxlint — fast JavaScript/TypeScript linter
  • oxfmt — fast JavaScript/TypeScript formatter
  • TypeScript

And configuration for saneish defaults, which can be extended

Most of these are the raw defaults/recommended settings from typescript, eslint and prettier.

IDE Usage

Usage VS Code

Install the oxc extension, then update settings.json:

"editor.defaultFormatter": "oxc.oxc-vscode",
"editor.formatOnSave": true,

Usage with IntelliJ

IntelliJ has an Oxc plugin supporting oxfmt and oxlint: https://plugins.jetbrains.com/plugin/27061-oxc

Project Usage

  1. Install @linzjs/style:
# this also installs dependencies: madge oxfmt oxlint oxlint-tsgolint
npm install --save-dev @linzjs/style
  1. Install the config files: There are two ways to apply the config

Either create the base configuration files

# If on windows run `node ./node_modules/@linzjs/style/build/src/install.js`
# - oxfmt.config.ts
# - oxlint.config.ts
# - tsconfig.json
npx linz-style-install

Or extend your existing oxlint.config.ts config

Example extending the oxlint.config.ts file in your project

import base from '@linzjs/style/oxlint.config-react';
import { defineConfig } from 'oxlint';

export default defineConfig({
  extends: [base],
  overrides: [
    {
      /** Overrides for typescript */
      files: ['**/*.ts', '**/*.tsx'],
      rules: {
        'react/super-crazy-hook-rule': 'error',
      },
    },
  ],
});
  1. Update package.json scripts

Add/update lint-related commands in package.json:

  scripts: {
    "lint": "npx concurrently \"npm run lint:circular\" \"npm run lint:oxlint\" \"npm run lint:fmt\" \"tsc\"",
    "lint:circular": "madge --circular --extensions js,ts,tsx --ts-config tsconfig.json ./src",
    "lint:oxlint": "oxlint --deny-warnings",
    "lint:fmt": "oxfmt --check .",
    "lint:fix": "oxlint --fix",
    "format": "oxfmt --write ."
  }
  1. Apply the formatting/linting to all source code
npm run lint .

Migration from 3.x to 4.x

See Migration Docs

Migration from 5.x to 6.x

See Migration Docs

About

LINZ {Java,Type}script style guide, with built in linting and formatting

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors