npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-config-postmodern

v1.0.5

Published

Javascript Postmodern Style - ESLint Shareable Config

Downloads

324

Readme

An ESLint Shareable Config for javascript postmodern style

Install

npm install eslint-config-postmodern

Usage

Shareable configs are designed to work with the extends feature of .eslintrc files. You can learn more about Shareable Configs on the official ESLint website.

To use the javascript postmodern style shareable config, first run this:

npm install --save-dev eslint-config-postmodern eslint-plugin-promise eslint-plugin-import eslint-plugin-node

Then, add this to your .eslintrc file:

{
  "extends": "postmodern"
}

You can override settings from the shareable config by adding them directly into your .eslintrc file.

Rules

So, what exactly does postmodern give you? First and foremost, semicolons are required to enforce readability. Beyond that, below is a visual guide to the rules. Code samples are taken straight from eslint.org. Second, postmodern follows eslint's recommended rules and, as such, those will not be listed below.

Arrow spacing

Require a space before/after arrow function's arrow:

(a) => {}
Brace style

Postmodern follows the one true brace style where the opening brace of a block is placed on the same line as its corresponding statement of declaration.

if (foo) {
  bar();
} else {
  baz();
}  
Camelcase

Postmodern follows camelcase (camelCase) rather than snake case (snake_case) for functions and variables. However, errors are not thrown if an object property is snake case as sometimes that is unavoidable.

function myNewFunction() {
  ...
}
const myVariable;
Comma Dangle

Postmodern disallows comma dangles for arrays, objects, imports, exports, and functions.

  const foo = {
    bar: 'baz',
    qux: 'quux' // No comma!
  };
  const arr = ['one', 'two'];  
Comma spacing

Requires a space after a comma

foo(a, b);
Comma Style

Requies a comma after and on the same line as an array element, or object property.

  const obj = {
    a: 1, // Comma is required to be on this line and not the following
    b: 2
  };  
Curly

Requires curly braces in cases where they can be omitted.

  if (foo) {
    foo++;
  }
  // Does not allow for if (foo) foo++;  
Dot location

Enforced for objects and properties, requires the dot should be on the same line.

  const foo = obj.property;
EOL last

Requires a newline at the end of a file

EQEQEQ

Requires === and !== in lieu of == and != to take advantage of type safety.

 if (x === 42) { // x == 42 throws an error
   ...
 };  
 if (y !== x) {
   ...
 };  
Function call spacing

Disallows a space between function identifiers and their invocations.

  new Date(); // new Date (); throws an error
Handle Callback Error

In node.js, a common pattern for dealing with asynchronous behavior is called the callback pattern. This pattern expects an Error object or null as the first argument of the callback.

  function loadData(err, data) {
    ...
  }  
Indent

Requires consistent indentation of code blocks. Postmodern requires two spaces.

  if (a) {
    b = c;
    const foo = (d) => {
      e = f;
    };
  }
  
  switch(a) {
    case 1:
      b = c;
      break;
    case 2:
      c = d;
      break;
    default:
      d = e;
      break;
  }            
Key spacing

Requires a space after a colon.

  const obj = {
    foo: 42 // Space required here
  };  

Keyword Spacing

Requires a space before and after syntax keywords such as as, async, await, break, case, catch, class, const, etc.

Bad formatting:

  if(foo) { // Error
    ...
  }else{ // Error
    ...
  }    

Correct:

  if (foo) {
    ...
  } else {
    ...
  }
  const a = 'b';
  await Promise.all(promises);
  let a = [100, this.foo, this.bar];   
New Cap

Requires all new operators to be called with uppercase-started functions

  const friend = new Person();
New Parens

Disallows the omission of parentheses when invoking a function via the new keyword.

   const person = new Person(); // Calling new Person results in an error
No Console

Gives a warning on the use of console.log, console.warn, console.error, etc.

Operator Linebreak

When a statement is too long to fit onto a single line, the operator follows on the next line.

  const fullHeight = borderTop
    + innerHeight
    + boderBottom;
Padded blocks

Block statements will never begin or end with a newline.

  if (a) {
    b();
  }  
Quotes

Only single quotes are accepted as valid.

Rest spread spacing

Disallows spacing the spread operator and its expression.

  let {x, y, ...z} = {x: 1, y: 2, a: 3, b: 4};
Semi spacing

Disallows spaces before semicolons but enforces them after.

  for (let i = 0; i < 10; i++) {
    ...
  }  
Space before Blocks

Blocks must always have at least one preceding space.

  if (a) {
    b();
  }
  
  function a() {
    ...
  }
  
  try {
    ...
  } catch(e) {
    ...
  }        
Space before Function Paren

Disallows spaces before the parentheses of a function

  function withoutSpace(x) { // Cannot use withSpace (a)
    ...
  }  
Space in Parens

Disallows spaces within parentheses

  foo('bar'); \\ Not foo( 'bar' );
  const foo = (1 + 2) * 3; // Not ( 1 + 2 )
Space infix Ops

Requires spacing around operators

  const sum = 1 + 2; // Not 1+2
Space Unary Ops

Requires spaces for words new, delete, typeof, void, yield

Spaced Comment

// must be followed by a space.

// See, the comment marker is followed by a space
Template Curly Spacing

Disallows spaces within ${}

  const template = `Disallow spaces within ${tempVar}`;