eslint-plugin-metafizzy

2.0.1 • Public • Published

eslint-plugin-metafizzy

ESLint config and custom rules for development on Metafizzy projects

I'm persnickety about my code style. While ESList captures 95% of what I want, there are some rules that I need to customize. See custom rules below.

Generally, I like spaces in braces and around operators

getItem( element )
[ x, y ]
1 + 2

But I also like no spaces for singular values that are already separated with syntax highlighting

getItem('hydrogen')
items[i]
TAU/4

I concede it's a bit idiosyncratic, but I find it easier to read.

Usage

Install with npm.

npm install eslint-plugin-metafizzy --save-dev

Add metafizzy to plugins in your ESLint config.

// .eslintrc.js
module.exports = {
  plugins: [
    'metafizzy',
  ],
};

Set extends to plugin:metafizzy/configName to use a plugin configuration. This plugin provies three configurations: browser, node, and base.

// .eslintrc.js
module.exports = {
  plugins: [
    'metafizzy',
  ],
  extends: 'plugin:metafizzy/browser',
};

See src/eslintrc.js for base configuration and src/index.js for

Custom rules

All three rules work in place of official ESLint rules. The official need to be disabled in order for these custom rules to work, which they are if your config extends plugin:metafizzy/configName.

metafizzy/spaces-in-parens

Enforces consistent spacing inside parentheses.

By default, parentheses have inside spaces.

getItem( element )
getItem( a, b )
getItem( [ x, y ], [ u, v ] )
getItem( 1 + 2 )
getItem( 'row' + rowNumber )

Parentheses with content that is a single String, Array, or Object have no spaces.

getItem('hydrogen')
getItem([ x, y ])
getItem({ bloodType: 'AB Positive' })

metafizzy/computed-property-spacing

Enforces spacing inside computed property brackets.

By default, properties have spaces inside brackets.

items[ index ]
items[ 10 + 4 ]
items[ 'last' + 'Index' ]

Properties that are numbers, single-character variables, or single strings have no spaces inside brackets.

items[1]
items[i]
items['hydrogen-element']

metafizzy/space-infix-ops

Enforces consistent spacing around operators.

Be default, operators have spaces around them.

1 + 2
var a = b
a ? b : c

The division operator /, when both preceeding and following value are either a number or singular variable have no spaces, so they appear more like a fraction.

1/2
TAU/4

MIT License. By Metafizzy 🌈🐻

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i eslint-plugin-metafizzy

    Weekly Downloads

    92

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    34.2 kB

    Total Files

    15

    Last publish

    Collaborators

    • desandro