README.md

goodparts

An ESLint Plugin that only allows JavaScript the Good Parts
(and "Better Parts") in your code so you can ship more reliable code.

Why?

Using JavaScript "The Good Parts" (abreviated to "goodparts")
is the best way we know
how to write simple, consistent,
predictable and 100% cross-browser-compatible JavaScript code.

The guiding principal of goodparts is:

"perfectionisattainednot when there is nothing more to add,
but when there isnothing more to remove" ~
Antoine de Saint-Exupéry

We agree that "code is for humans to read":

"Programs must be written for people to read,
and only incidentally for machines to execute." ~ Harold Abelson

"Any fool can write code that a computer can understand. Good programmers write code that humans can
understand." ~ Martin Fowler

The 3 biggest advantages of using goodparts in your code:

Readability - using fewer ECMAScript (JS) language features means
people reading your code can get to the heart of what it does
rather than waste time trying to understand
how its been written.

Portability -
"Old" Browsers/Devices are a fact, even if it's "only a small percentage"
of people, we chose to
empathize
with them by writing code that Works EverywhereTM.

Beginner-friendlyness or Shoshin - using fewer JS features
also means a complete beginner has less to learn before
they understand your code. This is essential in Open Source
if you want to make something that anyone can use/modify/extend.

What?

goodparts is a "linter"
that ensures your project's JavaScript code
only contains the subset of JavaScript known as "The Good Parts".
This guarantees that
your code works everywhere. (or your money back!)

Text Editor Linting Plugin?

While we're working on an atom plugin,
you can still use goodparts to lint your code in your editor using the
linter-eslint plugin for atom. To do this, you need a .eslintrc.js
file in your project that reflects the goodparts configuration.
Luckily we have a command line option for this too!

Simply run:

$ node_modules/.bin/goodparts /path/to/dir --link

This will create a symlink to the goodparts configuration file
at /path/to/dir/.eslintrc.js, which we recommend you add it to .gitignorefor now.

Pre Commit Hook

If you would like to add a pre-commit hook to check that your linting is up to scratch:

$ npm i -D pre-commit

Then, assuming you have added the lint script described above, add the following line to your package.json:

{
"pre-commit": ["lint"]
}

Repo Badge ?

If you use goodparts to lint your code and want to let other people know,
you can add this badge in your repo:

[![JavaScript Style Guide: Good Parts](https://img.shields.io/badge/code%20style-goodparts-brightgreen.svg?style=flat)](https://github.com/dwyl/goodparts "JavaScript The Good Parts")

(Frequently Asked) Questions?

Q: If the intention is to use only the Good Parts,
why not use JSLint and not bother with this tool?A: the simple answer is JSLint (DC's tool),
does not allow you to include a project-wide configuration
file, so you need to specify your environment e.g:
/*jslint node: true */ in every file, which gets old fast.

Why (extended version)

Why Should Anyone Listen to Douglas Crockford?

There are many places you can go to learn JavaScript,
unsurprisingly they all claim to teach you the "right way",
and as a beginner it's virtually impossible to detect
which is the "right" path because there is a lot of
marketing hype which can easily be mistaken for "fact".

The only way a beginner can determine if the source of
learning is any good is by listening to their their peers
or failing that, "gut feeling", neither of which are
a reliable measure of quality.

Crockford is the "Yoda"
of JavaScript, he has truly mastered the craft.
He is a member of "TC39"
(the ECMAScript Technical Committee) responsible for
setting the language standard to be implemented by web browser makers;
to say that DC "knows" JavaScript inside-out is an understatement.
He invented JavaScript Object Notation
("JSON")
data format (the Standard for REST APIs) and wrote the first JSON parser.
He painstakingly scoured the entire ECMAScript specification
in order to compile his list of Good (and Bad) Parts,
a subset of the language that can be trusted and
used reliably anywhere.
He has been lead engineer at Yahoo and Paypal and run his own
web consulting company specialising in JS applications.

Most people will not look at http://javascript.crockford.com
and think: "yes, this looks like the place to learn
JavaScript..." and that's a shame because its "plainness"
(lack of pictures or medium-style presentation) does not do justice to
the insight he shares.

Why does this matter / should I care?

If you are lucky enough to be building an internal web app
(*e.g: an intranet or "internal tools") and you "know" that
everyone in the company/organisation is using "Latest Chrome"
that's awesome,
thank your lucky stars and enjoy using all the latest & greatest features of
ES6!

If, like us, you live in the "real world" and build applications/websites
that need to be accessible by and work consistently on any device/browser,
then using only the goodparts is a good idea.

We are not suggesting that you (your team/company) should
(explicitly) support IE8 running on Windows XP! (heavens no!)
Simply that there is an easy way to ensure that your code will work
everywhere so you don't have to think about it.

ES2015?

The 6th edition JavaScript, officially known as "ES6" or ECMAScript 2015, was finalized in June 2015.
This update adds significant new syntax for writing complex applications, including classes and modules

Should We Use ECMAScript 2015 (AKA "ES6")?

When you see someone trying to use all the
latest features of ECMAScript 2015,

think/ask:

"will this code work everywhere?"

"did the users ask me to use this (new) language feature?
(or is there an existing way of doing this reliably...?)"

"if I'm just going to "transpile" this through babel or add a pollyfill
(for cross-browser compatibility) which means users have to load more bytes of code
in their browser (so pages take longer to load), what is true the advantage...?"

But caniuse.com says ...

Caniuse.com is a fantastic website. The UI is brilliant and for "informal"
(i.e. non-scientific) discussions about which HTML5 features are available
in a browser, we use it often! But caniuse.com bases it's pretty
graphs on the data from
statcounter.com which is good
but has severalflaws in data collection methodology:

Small sample size - StatCounter collects data for a
"_network of more than 3 million websites"
if you know anything about the internet you will realize that this
is a drop in the ocean.
3M sites is less than 0.3% of websites on the internet1.

Over counting - StatCounter counts all page views made by
a given user (agent) which means that heavy users have higher
representation in the sample.
(If the website does not work on a given browser/device
the person will obviously not get past the first page!)
By contrast NetMarketShare only counts the first pageview
which means it gives an equal weighting to each visitor.

1According to netcraft.com
there are over a billion (active) websites online in May 2016.
It is unclear which websites StatCounter is sourcing its data from,
please don't take their usage tables as "gospel" because they are flawed.

Browser Stats Facts

Most of us live in a technology bubble, we take it for granted
that we always have Wifi or 4G and assume that because many of our
friends/colleagues are using MacBook Pros or iPhone 6s that
everyone is in the same situation.

At the time of writing Internet Explorer 8still has a 5.95%
(global) Market Share (according to
netmarketshare.comApril 2016)

Even if we think that "everyone" has switched to Chrome,
the facts (stats) are clearly not supporting this hypothesis!

58% of people are still using an Operating System that is
no longer supported by Microsoft (Windows 7 & XP market share = 58.45%) ...
Microsoft ended "mainstream" support for Windows 7 on
Jan 13 2015
so even if they want to force everyone to upgrade to "Edge",
they cannot; which means we are relying on non-technical people to
manually upgrade their browser... If you have ever been in Tech support
and had a person ask "what is a browser?" you will know that
might take a while...