Skip to main content
Version: 5.x

ko-lint-config

ko-lint-config saves time in three ways for you:

  • No configuration - The easier way to enforce code quality in your project. No configuration rules. It just works.
  • Automatically format code - Just run pnpm lint-fix and say goodbye to messy or inconsistent code.
  • Catch style issues & programmer errors early - Reduce manual review in the code review process, and leave simple things to tools to save time.

No hesitation. No more maintenance .eslintrc. Give it a try right now!

Detailed rules

  • four spaces are required – indent
  • single quotation marks are required for string – except where escape is need
  • require keyword followed by space - if (condition) {...}
  • requires no spaces after the function name - function name (arg) {...} except anonymous functions and async function (arg) {...} `` async () { ... }
  • semicolons are not mandatory
  • not mandatory = = = - the field type returned by the backend cannot be guaranteed
  • do not force ternary operators to wrap
  • allow but do not require trailing commas - when the last element or attribute is on a different line from the end or attribute
  • function content is allowed to be empty
  • allow this alias - alias optional self _this `that', cannot be deconstructed from this
  • no debugger required
  • no console is recommended

Install

pnpm add ko-lint-config -D

Usage

How to get Code Style Guide: 如何引入 Code Style Guide

1、Then, add this to your .eslintrc.js.prettierrc.js.stylelintrc.js file:

module.exports = {
extends: [require.resolve('ko-lint-config')],
}
const prettier = require('ko-lint-config/.prettierrc')

module.exports = {
...prettier,
}
module.exports = {
extends: [require.resolve('ko-lint-config/.stylelintrc')],
}

You should not override settings. Because this is a Code Style Guide for group.

2、Add script to package.json:

"scripts": {
"lint": "npx eslint './src/**/*.ts' './src/**/*.tsx'",
"lint-fix": "npx eslint './src/**/*.ts' './src/**/*.tsx' --fix",
"lint-css": "npx stylelint './src/**/*.scss' './src/**/*.css'",
"lint-css-fix": "npx stylelint './src/**/*.scss' './src/**/*.css' --fix"
},

You can use pnpm lint-fix to correct most code style problems.

How do I disable a eslint rule?

In rare cases, you'll need to break a rule and hide the error generated by Code Style Guide.

ko-lint-config uses ESLint under-the-hood and you can hide errors as you normally would if you used ESLint directly. stylelint is same to eslint.

Disable all rules on a specific line:

file = 'I know what I am doing' // eslint-disable-line

Or, disable only the "no-use-before-define" rule:

file = 'I know what I am doing' // eslint-disable-line no-use-before-define

Or, disable the "no-use-before-define" rule for multiple lines:

/* eslint-disable no-use-before-define */
console.log('offending code goes here...')
console.log('offending code goes here...')
console.log('offending code goes here...')
/* eslint-enable no-use-before-define */

Looking for something easier than this?

You can add to your pnpm lint script and install eslint plugin for vscode.