All Projects → saadq → Lynt

saadq / Lynt

Licence: mit
✨ A zero config JavaScript linter with support for Typescript, Flow, and React.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Lynt

eslint-config
An ESLint shareable config that I used in my projects
Stars: ✭ 15 (-96.15%)
Mutual labels:  eslint, tslint, linter
Lint Review
An automated code linting bot that integrates various code lint tools with github pull requests.
Stars: ✭ 279 (-28.46%)
Mutual labels:  eslint, linter, tslint
arcanist-linters
A collection of custom Arcanist linters
Stars: ✭ 64 (-83.59%)
Mutual labels:  eslint, linter
codeclimate-eslint
Code Climate Engine for ESLint
Stars: ✭ 86 (-77.95%)
Mutual labels:  eslint, linter
Tslint Config Standard
A TSLint config for JavaScript Standard Style
Stars: ✭ 358 (-8.21%)
Mutual labels:  eslint, tslint
Eslint
Find and fix problems in your JavaScript code.
Stars: ✭ 19,665 (+4942.31%)
Mutual labels:  eslint, linter
TSLint.MSBuild
[Deprecated] An MSBuild task for running TSLint.
Stars: ✭ 13 (-96.67%)
Mutual labels:  tslint, linter
eslint-config-kingstinct-react-native
Eslint configuration for React-native based on Airbnb with some great tweaks
Stars: ✭ 23 (-94.1%)
Mutual labels:  eslint, linter
elint
A easy way to lint your code
Stars: ✭ 38 (-90.26%)
Mutual labels:  eslint, linter
gandalf-lint
Bad Code Shall Not Pass
Stars: ✭ 29 (-92.56%)
Mutual labels:  eslint, linter
awesome-react-app
Always the latest version of "create-react-app" with awesome configurations (lint, commit lint, husk, editor config, etc)
Stars: ✭ 44 (-88.72%)
Mutual labels:  eslint, linter
ts-standard
Typescript style guide, linter, and formatter using StandardJS
Stars: ✭ 338 (-13.33%)
Mutual labels:  tslint, linter
spec
🐣 easy to use eslint/stylelint/tslint/prettier/...
Stars: ✭ 60 (-84.62%)
Mutual labels:  tslint, linter
web-build-tool-demo
比较全面的前端构建工具demo,拿来即练,不定时更新,包含git npm gulp webpack babel typescript husky eslint tslint lint-stage prettier等
Stars: ✭ 42 (-89.23%)
Mutual labels:  eslint, tslint
Eslint Plugin Markdown
Lint JavaScript code blocks in Markdown documents
Stars: ✭ 242 (-37.95%)
Mutual labels:  eslint, linter
Codestyle
JavaScript and TypeScript Style Guide
Stars: ✭ 207 (-46.92%)
Mutual labels:  eslint, tslint
Eslint Config Standard
ESLint Config for JavaScript Standard Style
Stars: ✭ 2,229 (+471.54%)
Mutual labels:  eslint, linter
Grunt Eslint
Validate files with ESLint
Stars: ✭ 189 (-51.54%)
Mutual labels:  eslint, linter
standard-packages
List of packages that use `standard`
Stars: ✭ 32 (-91.79%)
Mutual labels:  eslint, linter
Typescript Tslint Plugin
TypeScript TSLint language service plugin
Stars: ✭ 270 (-30.77%)
Mutual labels:  linter, tslint

lynt

A zero config JavaScript linter with support for React, Flow, and Typescript.

Build Status linter: lynt style: prettier tests

Lynt has two main philosophies:

  1. Zero configuration by default. Out of the box, Lynt is a working linter and does not need any configuration. However, if you would like to add or remove rules from the default Lynt config, you have the option to do so.
  2. No style rules. Lynt is completely unopinionated when it comes to code style. It doesn't care whether or not you use semicolons, tabs or spaces, trailing commas, etc. Lynt only handles the error checking side of things and it leaves code style up to better-suited tools like prettier.

The real value of ESLint is in the non-style rules that prevent common errors.

– Nicholas C. Zakas, the creator of ESLint.


output

How It Works

Under the hood, Lynt uses ESLint and TSLint to lint your files.

It will know which linter to use as well as which rules/parsers/ignores/etc to apply based on the options you pass to it.

Installation

Make sure you have node and npm installed first.

You can install the package locally for a single project:

$ npm install lynt --save-dev

Or you can install it globally (not recommended):

$ npm install lynt --global

Usage

If you want to lint all your project files, you can just run the lynt command by itself.

Add a script to your package.json:

{
  "scripts": {
    "lint": "lynt"
  }
}

And then run the script in your terminal whenever you want to lint your code:

$ npm run lint

By default, folders like dist and node_modules are ignored.

If you only want to lint a subset of your project or individual files, you can pass globs:

{
  "scripts": {
    "lint": "lynt src/**/*.js"
  }
}

You can use flags to add support for Flow, React, or TypeScript. For example, if you were using TypeScript and React, you can set your lint script to:

{
  "scripts": {
    "lint": "lynt --typescript --react"
  }
}

You can see a full list of flags you can pass to lynt in the CLI section.

Notes on TypeScript Usage

Lynt uses TSLint to lint TypeScript files, and some TSLint rules need to get information from your project's tsconfig.json file.

If your tsconfig.json is in your root project folder, just run:

$ lynt --typescript

If your tsconfig.json file is somewhere else (for example, ./config/tsconfig.json, you can point to it with a --project flag.

$ lynt --typescript --project config

If you have lynt installed globally and are trying to use it with --typescript, you will need to make sure that you have typescript installed globally as well.

CLI

  Usage
    $ lynt [files] <options>

  Options
    --typescript   Add support for TypeScript.
    --flow         Add support for FlowType.
    --react        Add support for React.
    --ignore       Glob patterns for paths to ignore.
    --fix          Automatically fix linting issues.
    --global       Add support for a given global variable.
    --env          Add support for a given environment.
    --json         Get lint results in JSON format instead of default "stylish" format.
    --project      Specify your project's main directory if it isn't in the root (only use with --typescript).

  JavaScript Examples
    $ lynt
    $ lynt --react
    $ lynt --react --flow --env jest
    $ lynt src
    $ lynt src --ignore out/**/*.* --ignore tests/**/*.*
    $ lynt src --global chrome --global atom

  TypeScript Examples
    $ lynt --typescript
    $ lynt --typescript --react
    $ lynt --typescript --project .
    $ lynt src --typescript
    $ lynt src --typescript --ignore out/**/*.* --ignore tests/**/*.*

Configuration

You can specify your Lynt configuration in one of three ways:

  1. Use CLI flags:
$ lynt --typescript --react --ignore tests/**/*.* --ignore fixtures/**/*.*
  1. Have a "lynt" property in your package.json:
{
  "lynt": {
    "typescript": true,
    "react": true,
    "ignore": ["tests/**/*.*", "fixtures/**/*.*"]
  }
}
  1. Have a .lyntrc file in your root project folder:
{
  "typescript": true,
  "react": true,
  "ignore": ["tests/**/*.*", "fixtures/**/*.*"]
}

Rule Configuration

If you want to turn off any of the default lynt rules, or add your own custom rules, you can add a rules object in your configuration. Note that rule configuration cannot be done from the CLI, you must use a lynt property in package.json or use a .lyntrc file.

Disabling a default rule

You can set a value to 'off' to turn off a default rule.

{
  "rules": {
    "curly": "off",
    "no-unused-vars": "off"
  }
}

Adding a rule

If you want to add a rule, you can set it to on to use the rule's default setting, or set it to something more complicated.

{
  "rules": {
    "prefer-const": "on",
    "no-console": "on",
    "no-magic-numbers": ["error", { "ignore": [1] }]
  }
}

Note: Style rules will still be ignored.

API

import lynt, { format } from 'lynt'

or

const { default: lynt, format } = require('lynt')

lynt(files[, options]) => LyntResults

Uses ESLint or TSLint to lint a given set of files. Returns an array of LyntResult objects (see below to see its properties).

  • files – A string or array of strings of file paths to lint. Required.
  • options – A configuration object that lets you customize how lynt works. Optional

Here are the possible options you can pass:

{
  typescript?: boolean
  flow?: boolean
  react?: boolean
  ignore?: string | Array<string>
  fix?: boolean
  global?: string | Array<string>
  env?: string | Array<string>
  json?: string | Array<string>
  project?: string,
	rules?: {
		[ruleName: string]: any
	}
}

See the CLI section to see a detailed description of what each option is for.

Example (no options):

import lynt from 'lynt'

const results = lynt(['foo.js', 'bar.js'])
console.log(results)

Example (with options):

import lynt from 'lynt'

const options = {
  flow: true,
  react: true,
  rules: {
    'no-unused-vars': 'off'
  }
}

const results = lynt(['foo.js', 'bar.js'], options)
console.log(results)

LyntResult Example:

{
  filePath: string
  errors: Array<{
    ruleName: string
    message: string
    line: number
    column: number
    endLine?: number
    endColumn?: number
  }>
  errorCount: number
  fixCount: number
}

format(lintResults) => string

Formats an array of LyntResult objects (like the one returned from calling lynt()) into a nice looking table.

  • lintResults – An array of LyntResult objects.

Example:

import lynt, { format } from 'lynt'

const results = lynt(['foo.js', 'bar.js'])
const table = format(results)

console.log(table)

Badge

You can show off that your project uses Lynt with this badge:

linter: lynt

Just put the following in your README:

[![linter: lynt](https://img.shields.io/badge/linter-lynt-E81AAF.svg)](https://github.com/saadq/lynt)

FAQ

Why not standard or xo?

I think these are awesome projects, and I have been a user of both. I definitely drew a lot of inspiration from them – however, one the main philosophies of lynt was to be an error-checker, not a style guide. Both standard and xo are very opinionated when it comes to style. xo is actually configurable, so you can manually remove all the style rules, but it is still troublesome when trying to use it with TypeScript and Flow – with lynt it is seamless.

Are the current rules set in stone?

While lynt is still in v0.X, the rules are considered to be tentative – there will probably be rules being added in and removed. Once Lynt reaches a point where most are happy with the rules, v1 will be released and rules will change a lot less often. New rules will be added as ESLint and TSLint introduce them though and will be introduced to Lynt as a major version upgrade. However, at no point will any style rules be accepted as part of lynt.

How can I voice my opinion about some of the linting rules?

The best way would be to open up a GitHub issue and people will be able to chime in with their opinion.

Are there any editor plugins?

Unfortunately, I haven't gotten around to trying to make any yet. I can definitely use some help in this department, so if anyone would like to try to make a plugin for their favorite editor it would be greatly appreciated! Also, please let me know if there's anything I can improve with the API in order to make editor integration easier.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].