Code Monkey home page Code Monkey logo

eslint-plugin-metafizzy's Introduction

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 ๐ŸŒˆ๐Ÿป

eslint-plugin-metafizzy's People

Contributors

dependabot[bot] avatar desandro avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kant isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.