• Stars
    star
    117
  • Rank 300,637 (Top 6 %)
  • Language
    JavaScript
  • Created almost 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ’› ESLint config that only helps you, and otherwise stays out of your way

eslint-config-unobtrusive

Problem

ESLint is a great tool, but people too often abuse it.

Although a linter can be a helpful companion when you are new to a language, it can get in the way once you are more familiar with the language.

Even worse, misguided linter rules can teach a user to fear patterns which aren't problematic in practice.

I got tired of ESLint configs that included annoying rules that would yell at me even though the code would work just fine as written.

I wanted an ESLint config that would stay silent most of the time, but when it spoke up, it would be helpful rather than annoying. Thus, unobtrusive was born.

Goals

unobtrusive was made with the following goals in mind:

  • Stay out of the user's way, but still offer help.
  • Don't flag anything based on arbitrary consistency, stylistic choices, or premature optimization.
  • Help the user find unfinished or unused code while they type.
  • Help the user find typos and mistakes.
  • Only flag something with severity "error" if it would cause a runtime error. Otherwise, "warn" should be used.
  • Only flag something if ESLint has a high level of confidence that the code contains a mistake, problem, is unused, or the result of incomplete refactoring. Err on the side of not flagging rather than creating false positives.
  • Ideally, the user should never have to use eslint-disable comments.

Assumptions

This config assumes the following:

  • You are using ECMAScript modules in your codebase.
  • Since you are using modules, your code is implcitly in strict mode.
  • You aren't using nonstandard globals very often, but when you do, you define them in your eslint config.
  • You'll define env in your eslint config yourself.

Rationale

These are the criteria I used to decide which rules to include:

  • Disable all formatting rules (such as indent).
    • ESLint can't standardize code style perfectly; lots of variations can still slip through the cracks. Use a code formatter (like prettier) or style guide (like standard) instead.
  • Disable rules that require the user to change their code where doing so will not result in a change in runtime behavior (such as yoda, curly, and dot-notation).
    • These rules often seek to make things consistent for the sake of consistency alone, which is a waste of the user's time.
    • This rule can be broken if the user was likely to make this change themselves because the code was leftover or unused as a result of refactoring.
  • Disable rules that enforce "best practices" which may be subjective or not always apply (such as eqeqeq and class-methods-use-this).
    • These rules, while presumably well-intentioned, are often not a suitable stand-in for a user's judgement on a case-by-case basis. In situations where the "best practice" being enforced is something the developer has considered and is choosing not to do, these rules flagging the user's code can be very annoying and undermine the user's relationship with the linter (or the person who configured the linter).
  • Disable rules that get in the way while debugging, such as no-console.
    • The linter yelling at the user every time they debug code is very annoying, and creates an unnecessary negative association with debugging code.
    • Also, some users prefer to leave console.logs in their codebase.
    • Even though these rules are annoying while debugging, they can still be useful to prevent committing unintended debugging statements into the codebase. I chose to opt for a better editor experience here, but if you want to use these rules for that purpose, you can configure eslint to use a different config in the editor than in a git pre-commit hook or CI run.
  • Enable rules that help find typos and point out incomplete code, such as no-undef.
    • When writing code, it's nice to be able to rely on the linter to show which spots you haven't addressed yet, because when you're done writing, the linter messages should go away. The linter helps you keep track of what still needs to be done, so if you forget something or lose your place, the linter can often give you a hint.
  • Enable rules that help find unused or leftover code, such as no-unused-expressions.
    • When you are refactoring code, it's nice to rely on the linter to point out which parts are no longer used or need to be updated. The linter will help you keep track of things that don't line up right yet, and when you're done refactoring, the linter messages should go away.

Also, in the config itself (index.js), each rule has a comment above it explaining my thought process behind turning it either on or off. I have included every eslint rule in the config, even if I am setting it to the default value, so that you can understand the reasoning behind the decision.

Installation

  1. Install the package

    $ npm install eslint-config-unobtrusive
    
  2. Add it to your eslint config:

    .eslintrc

    {
      "extends": "unobtrusive",
      "env": {
        "browser": true
      }
    }
  3. That's it!

Note: Globals

The env config option is required, because eslint-config-unobtrusive includes the no-undef rule, which warns you when you access a variable that is not defined. In order to know which variables are defined, ESLint looks for variable declarations in the same file and also references a list of known globals. The env config option is used to configure the list of known globals in your environment.

You can also use the globals option to add additional names to the list of known globals:

{
  "extends": "unobtrusive",
  "env": {
    "browser": true
  },
  "globals": {
    "jQuery": false,
    "selectedColor": true
  }
}

The key/value pairs of the globals option refer to the name of the global and whether it is writable (so false indicates that the global is read-only).

Extras

unobtrusive also comes with some extra configs that you can add to get additional functionality. They follow the same philosophy as unobtrusive, but aren't enabled by default because they might not work out-of-the-box for every user.

unobtrusive/import

This extra config depends on eslint-plugin-import and adds rules that warn you when attempting to import or require things that don't exist. It's not included in the base unobtrusive config because it would flag false positives for users relying on custom import resolution mechanics, like webpack loaders or NODE_PATH.

Installation/Usage

  1. Install unobtrusive first

  2. Install eslint-plugin-import

    $ npm install eslint-plugin-import
    
  3. Add unobtrusive/import to your eslint config:

    .eslintrc

    {
      "extends": ["unobtrusive", "unobtrusive/import"],
      "env": {
        "browser": true
      }
    }
  4. That's it!

unobtrusive/react

This extra config depends on eslint-plugin-react and adds React-specific rules that are in line with the unobtrusive philosophy. It also configures eslint so that it can parse JSX properly, and fixes some JSX-related false positives and false negatives with no-unused-vars and no-undef. It's not included in the base unobtrusive config because not all users use React.

Installation/Usage

  1. Install unobtrusive first

  2. Install eslint-plugin-react

    $ npm install eslint-plugin-react
    
  3. Add unobtrusive/react to your eslint config:

    .eslintrc

    {
      "extends": ["unobtrusive", "unobtrusive/react"],
      "env": {
        "browser": true
      }
    }
  4. That's it!

unobtrusive/flowtype

This extra config depends on eslint-plugin-flowtype and babel-eslint and adds flow-specific rules that are in line with the unobtrusive philosophy. It also configures eslint so that it can parse flow types properly, and fixes some type-related false positives and false negatives with no-unused-vars and no-undef. It's not included in the base unobtrusive config because not all users use flow.

Installation/Usage

  1. Install unobtrusive first

  2. Install eslint-plugin-flowtype and babel-eslint

    $ npm install eslint-plugin-flowtype babel-eslint
    
  3. Add unobtrusive/flowtype to your eslint config:

    .eslintrc

    {
      "extends": ["unobtrusive", "unobtrusive/flowtype"],
      "env": {
        "browser": true
      }
    }
  4. That's it!

NOTE: To use unobtrusive, unobtrusive/import, unobtrusive/react, and unobtrusive/flowtype together, your eslint config would look like this:

{
 "extends": [
   "unobtrusive",
   "unobtrusive/import",
   "unobtrusive/react",
   "unobtrusive/flowtype"
 ],
 "env": {
   "browser": true
 }
}

More Repositories

1

hex-engine

A modern 2D game engine for the browser.
TypeScript
661
star
2

fs-remote

๐Ÿ“ก Drop-in replacement for fs that lets you write to the filesystem from the browser
JavaScript
235
star
3

switch-joy-con

Use Nintendo Switch Joy-Cons as input devices (Bluetooth)
JavaScript
196
star
4

safety-match

Rust-style pattern matching for TypeScript
TypeScript
178
star
5

pheno

Simple, lightweight at-runtime type checking functions, with full TypeScript support
TypeScript
129
star
6

chai-jest-snapshot

Chai assertion that provides Jest's snapshot testing
JavaScript
101
star
7

suchibot

A cross-platform AutoHotKey-like thing with TypeScript as its scripting language
TypeScript
99
star
8

react-state-tree

Drop-in replacement for useState that persists your state into a redux-like state tree
TypeScript
98
star
9

yavascript

shell script replacement; write shell scripts in js instead of bash, then run them with a single statically-linked file
TypeScript
76
star
10

react-testing-example-lockscreen

JavaScript
72
star
11

react-send

๐Ÿ“จ Separate your component's markup from their position in the render tree
JavaScript
70
star
12

test-it

Test-It is a test framework that gives you the best of node AND the browser.
TypeScript
53
star
13

equivalent-exchange

Transmute one JavaScript string into another by way of mutating its AST. Powered by babel and recast.
TypeScript
52
star
14

transform-imports

Tools that make it easy to codemod imports/requires in your JS
JavaScript
50
star
15

describe-component

๐Ÿ““ Consistent React unit testing with zero boilerplate!
JavaScript
46
star
16

grep-ast

CLI tool to grep files for AST patterns using css-like selector strings
JavaScript
41
star
17

gmod-server-docker

Garry's Mod server running in a docker container, with a volume exposed for customization
Shell
37
star
18

quinci

๐Ÿคต Self-hosted, minimal GitHub CI server
JavaScript
34
star
19

webview

A cross-platform program that opens either a URL or files from disk in a native webview.
Go
28
star
20

half-life-vox-console

Website where you can make Half Life's VOX say stuff
JavaScript
27
star
21

eslint-plugin-esquery

Simple, user-created ESLint rules, right in their eslint config
JavaScript
22
star
22

line-sticker-downloader

Tool that downloads stickers or emojis from the LINE store
JavaScript
22
star
23

require-browser

Easy-to-use require function for your browser
JavaScript
21
star
24

use-legacy-state

๐Ÿฆ… Custom React hook; drop-in replacement for this.setState
JavaScript
20
star
25

prs-merged-since

CLI and JS API to list all PRs merged into a GitHub repo since a given tag
JavaScript
19
star
26

run-on-server

๐Ÿ‘ฉโ€๐Ÿ’ป API generator that lets you write code as if you had serverside eval on the client
JavaScript
18
star
27

serializable-types

Runtime type assertion and serialization system
JavaScript
15
star
28

glomp

Lightweight, clearly-defined alternative to file glob strings
TypeScript
15
star
29

popularity-contest

Find the most-imported symbols in your JavaScript project
JavaScript
13
star
30

webview-node

Node wrapper around suchipi/webview.
JavaScript
13
star
31

react-boxxy

๐Ÿ“ฆ An extendable base component for React DOM.
JavaScript
12
star
32

arkit-face-blendshapes

A website which shows examples of the various blendshapes that can be animated using ARKit.
JavaScript
12
star
33

atom-morpher

Atom Package that helps you run code transformations on the current buffer
JavaScript
11
star
34

convert-to-dts

Convert some JavaScript/TypeScript code string into a .d.ts TypeScript Declaration code string
TypeScript
11
star
35

nice-path

treat filesystem paths as objects and distinguish between relative/absolute paths
TypeScript
10
star
36

simple-codemod-script

How to write your own JS/TS codemods, with comments and resources
TypeScript
10
star
37

parallel-park

Parallel/concurrent async work, optionally using multiple threads or processes
TypeScript
10
star
38

cleffa

CLI utility that parses argv, loads your specified file, and passes the parsed argv into your file's exported function. Supports ESM/TypeScript/etc out of the box.
JavaScript
10
star
39

mark-applier

Markdown-to-Website Generator, GitHub README style
TypeScript
10
star
40

has-shape

Very tiny function that checks if an object/array/value is shaped like another, with TypeScript type refining.
JavaScript
9
star
41

match-discriminated-union

TypeScript pattern match function for any discriminated union type
TypeScript
8
star
42

iterate-all

Converts an iterable, iterable of Promises, or async iterable into a Promise of an Array.
TypeScript
8
star
43

resolve-everything

walk your project's import/require tree and print all the relationships
TypeScript
8
star
44

Polycode-Binaries

Precompiled binaries of the Polycode Lua IDE
7
star
45

concubine

Create your own hooks system like React's
TypeScript
7
star
46

jsxdom

JSX factory that creates HTML elements directly
TypeScript
7
star
47

little-api

A simple JSON-over-HTTP/WebSocket RPC server and client
JavaScript
7
star
48

markdown-slice

tool that prints a subset of a markdown document
TypeScript
7
star
49

xode

Create a customized node binary with additional features
JavaScript
7
star
50

jsh

Tool for writing shell scripts using js.
JavaScript
7
star
51

clip-studio-paint-joycon

Use a Nintendo Switch Joy-Con (L) for Clip Studio Paint hotkeys
JavaScript
7
star
52

pretty-print-error

Formats errors as nice strings with colors
TypeScript
6
star
53

tf2-server-docker

TF2 Server running in a docker container
Dockerfile
6
star
54

kame

A JavaScript bundler/runtime
JavaScript
6
star
55

suchipi-game-controller

Wrapper around the Web Gamepad API
JavaScript
6
star
56

sheep-herder

A game where you're a dog who herds sheep
TypeScript
6
star
57

pokemon-red-intro-recreation

I recreated the Pokemon Red Intro in the browser
TypeScript
6
star
58

yosh

yavascript-based terminal shell
TypeScript
6
star
59

hex-engine-example-hexagon-grid

Example of rendering and interacting with a hexagonal grid in hex engine.
TypeScript
6
star
60

spotify-player

Node API to drive a Spotify browser window
JavaScript
6
star
61

webview-packager

Bundles your web app into a light, native desktop webview application.
JavaScript
6
star
62

lurantis

on-demand module bundler thingy
TypeScript
6
star
63

typescript-assert-utils

Utility types for making assertions about TypeScript types
TypeScript
6
star
64

pretty-print-ast

Formats ASTs as nice readable strings, with colors
TypeScript
5
star
65

commonjs-standalone

Standalone CommonJS loader for any JS engine
JavaScript
5
star
66

hex-engine-tic-tac-toe-example

An example tic-tac-toe game written in Hex Engine.
TypeScript
5
star
67

aseprite-loader

Webpack loader for *.ase/*.aseprite files
JavaScript
5
star
68

js-is

Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values.
TypeScript
5
star
69

get-nested-bounding-client-rect

Get the bounding client rect of an element relative to the root document, going through iframes
JavaScript
5
star
70

peep-the-horror

A toy you can use to make an impromptu soundboard out of a video (YouTube, etc).
TypeScript
4
star
71

reverse-proxy-cli

barebones reverse-proxy CLI for forwarding requests from one place to another
JavaScript
4
star
72

node-apng2gif

Convert APNG images to GIF
JavaScript
4
star
73

code-preview-from-error

Preview the code an Error came from
JavaScript
4
star
74

clefairy

Typed CLI argv parser and main function wrapper
TypeScript
4
star
75

at-js

Unix command-line utilities for working with data
JavaScript
4
star
76

girlboss-advance

(wip) remote multiplayer gba emulator web interface
Dockerfile
4
star
77

ac-toolkit

Elements that assist in creating animal-crossing-like UI experiences
HTML
4
star
78

midi-to-thirty-dollar-haircut

(bad) script that converts midi files into *.๐Ÿ—ฟ files for https://gdcolon.com/%F0%9F%97%BF
TypeScript
4
star
79

tts-repl

simple interactive text-to-speech CLI program (shells out to AWS CLI for Amazon Polly and plays with ffplay)
TypeScript
4
star
80

js-sandbox-demo

Using QuickJS to implement a sandbox wherein it's safe to execute untrusted JavaScript code.
TypeScript
4
star
81

join

tiny CLI tool: JSON array to stdin -> join with delimiter -> string to stdout
Shell
4
star
82

visualize-ansi-codes

Replace ansi escape sequences with tokens indicating what they are.
TypeScript
3
star
83

extname

command-line utility for finding the extension of a filename/filepath
C
3
star
84

docker-bgb

BGB (GB/GBC Emulator) in docker via web vnc client (no sound)
Dockerfile
3
star
85

jest-node-nw-example

Jest in NW.js
JavaScript
3
star
86

defer

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.
TypeScript
3
star
87

shinobi

generate ninja build files from js scripts
TypeScript
3
star
88

babel-compare

Compare compilation output between babel 6 and babel 7
TypeScript
3
star
89

bibarel

walk over a tree, transforming each value
TypeScript
3
star
90

modal-synthesis

Package for synthesizing modal sounds using the Web Audio API
TypeScript
3
star
91

workspace-builder

CLI tool that run builds for every yarn workspace in your monorepo
JavaScript
3
star
92

first-base

Integration testing for CLI applications
JavaScript
3
star
93

discord-spotify-bot

Discord bot that plays Spotify in the voice channel
JavaScript
3
star
94

pipe-wrench

Generic, cross-platform IPC streams. Uses named pipes on windows and unix sockets elsewhere
JavaScript
3
star
95

a-mimir

Barebones sleep functions. As simple and boring as it gets
JavaScript
3
star
96

qjsbundle

TypeScript
3
star
97

link-fixer-discord-bot

Discord Bot: when someone posts a message with a twitter.com or x.com link, it replies with a vxtwitter.com version of that link
TypeScript
3
star
98

multi

Redux + Quake-style Netcode = ???
TypeScript
2
star
99

babel-plugin-transform-class-inherited-hook

Babel plugin that lets you hook class inheritance
JavaScript
2
star
100

domdom-go

Cross-platform CLI interface to DomDomSoft Anime Downloader
Go
2
star