Giter VIP home page Giter VIP logo

es-check's Introduction

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

This software is maintained under a new repository located at yowainwright/es-check

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️


ES Check ✔️


Check JavaScript files ES version against a specified ES version 🏆


Build Status npm version Greenkeeper Codecov Share on Twitter


ES Check ✔️

Version 5 release! 🎉 Thanks to @BrandonOCasey. Removes need for boolean in argument; post Caporal 1.1.0. This will require an update for any boolean cli flags, in example --module, --allow-hash-bang.

Example of CLI boolean flag in previous versions (Versions 0-4.*)

// the "true" argument was required
es-check --module true es6 ./tests/modules/*.js'

Now, with Version 5

// the "true" argument must be removed if used
es-check --module es6 ./tests/modules/*.js'

ES Check checks JavaScript files against a specified version of ECMAScript (ES) with a shell command. If a specified file's ES version doesn't match the ES version argument passed in the ES Check command, ES Check will throw an error and log the files that didn't match the check.

Ensuring that JavaScript files can pass ES Check is important in a modular and bundled world. Read more about why.


Get Started   Why ES Check?   Usage   Walk Through   API   Debugging   Contributing   Issues


Get Started

Install

npm i es-check --save-dev   # locally
npm i es-check -g           # or globally

Check if an array or glob of files matches a specified ES version.

  • Note: adds quotation around globs. Globs are patterns like so, <something>/*.js.
es-check es5 './vendor/js/*.js' './dist/**/*.js'
  • The ES Check script (above) checks /dist/*.js files to see if they're ES5. It throws an error and logs files are that do not pass the check.

Why ES Check?

In modern JavaScript builds, files are bundled up so they can be served in an optimized manner in the browsers. It is assumed by developers that future JavaScript—like ES8 will be transpiled (changed from future JavaScript to current JavaScript) appropriately by a tool like Babel. Sometimes there is an issue where files are not transpiled. There was no efficient way to test for files that weren't transpiled—until now. That's what ES Check does.


Walk through

The images below demonstrate command line scripts and their corresponding logged results.

Pass pass

Fail fail

ES Check is run above with node commands. It can also be run within npm scripts, ci tools, or testing suites.


API

ES Check provides the necessities. It accepts its place as a JavaScript matcher/tester.

General Information

# USAGE

index.js es-check <ecmaVersion> [files...]

Arguments

<ecmaVersion> 'define the ECMAScript version to check for against a glob of JavaScript files' required
[files...] 'a glob of files to test the ECMAScript version against' required

Options

Modules Flag

--module use ES modules, default false

Allow Hash Bang

--allow-hash-bang supports files that start with hash bang, default false

Not

--not=folderName1,folderName2 An array of file/folder names that you would like to ignore. Defaults to `[]`.

Global Options

-h, --help         Display help
-V, --version      Display version
--no-color         Disable colors
--quiet            Quiet mode - only displays warn and error messages
-v, --verbose      Verbose mode - will also output debug messages

Usage

ES Check is a shell command CLI. It is run in shell tool like Terminal, ITerm, or Hyper. It takes in two arguments: an ECMAScript version (<ECMAScript version>) and files ([files]) in globs.

Here are some example of es check scripts that could be run:

# globs
es-check ./js/*.js

# array of arguments
es-check ./js/*.js ./dist/*.js

Configuration

If you're using a consistent configuration, you can create a .escheckrc file in JSON format with the ecmaVersion and files arguments so you can conveniently run es-check standalone from the command line.

Here's an example of what an .escheckrc file will look like:

{
  "ecmaVersion": "es6",
  "module": false,
  "files": "./dist/**/*.js"
}

⚠️ NOTE: Using command line arguments while there is an .escheckrc file in the project directory will override the configuration values in .escheckrc.

Debugging

As of ES-Check version 2.0.2, a better debugging interface is provided. When a file errors, An error object will be logged with:

  • the erroring file
  • the error
  • the error stack

⚠️ NOTE: Error logs are from the Acorn parser while parsing JavaScript related to specific versions of ECMAScript. This means error messaging is not specific to ECMAScript version. It still offers context into parsing issues!


Acknowledgements

ES Check is a small utility using powerful tools that Isaac Z. Schlueter, Marijn Haverbeke, and Matthias Etienne built. ES Checker by Ruan YiFeng checks the JavaScript version supported within a browser at run time. ES Check offers similar feedback to ES Checker but at build time and is specific to the product that is using it. ES Check was started after reading this post about [deploying es2015 code to production today] by Philip Walton.


Contributing

ES Check has 3 main dependencies: acorn, glob, and caporal. To contribute, file an issue or submit a pull request.

Contributors

es-check's People

Contributors

brandonocasey avatar briangonzalez avatar dependabot[bot] avatar greenkeeper[bot] avatar gui avatar heythisispaul avatar jakiestfu avatar jeffbski avatar jrbalsano avatar mrbenj avatar renovate[bot] avatar ryanep avatar shellbj avatar someguynamedmatt avatar sudo-suhas avatar yowainwright avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

es-check's Issues

ignore node_modules

I have a problem: es-check tries to validate js files inside my node_modules folder. How to ignore that folder?

I have a monorepo, so, I have multiple node_moudles across my repo.

Support ES2015 modules

es-check ./src/**/*.mjs:

ES-Check: there were 22 ES version matching errors.

          ES-Check Error:
          ----
          · erroring file: ./src/annotations/annotation.iframe.mjs
          · error: SyntaxError: The keyword 'import' is reserved (1:0)
          · see the printed err.stack below for context
          ----

          SyntaxError: The keyword 'import' is reserved (1:0)

Proposed CLI: es-check --experimental-modules ./src/**/*.mjs or es-check --experimental-modules ./src/index.mjs. The latter points to the main file which import the rest of the app.

Also test dependencies

Requested Update

It would be handy if es-check could also check all required/imported files as well. I tried to run es-check es5 ./dist/index.js and it said it was no matching errors, but when I included my module in a react-app in complained that one of my dependencies was not in ES5.

Why Is This Update Needed?

To make sure the entire module and not a single file is in ES5.

Are There Examples Of This Requested Update Elsewhere?

Read about references issues here. Provide paragraph text responses to each header.

es-check fails on async arrow function

Requested Update

bugfix

crashes with this source code in file (a.js)

CLI launch: npx es-check es6 a.js

module.exports = async (foo) => alert('foo');

stacktrace

ES-Check: there were 1 ES version matching errors.

          ES-Check Error:
          ----
          · erroring file: a.js
          · error: SyntaxError: Unexpected token (1:29)
          · see the printed err.stack below for context
          ----

          SyntaxError: Unexpected token (1:29)
    at Parser.pp$4.raise (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/acorn/dist/acorn.js:2769:13)
    at Parser.pp.unexpected (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/acorn/dist/acorn.js:680:8)
    at Parser.pp.semicolon (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/acorn/dist/acorn.js:657:64)
    at Parser.pp$1.parseExpressionStatement (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/acorn/dist/acorn.js:1127:8)
    at Parser.pp$1.parseStatement (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/acorn/dist/acorn.js:851:24)
    at Parser.pp$1.parseTopLevel (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/acorn/dist/acorn.js:739:23)
    at Parser.parse (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/acorn/dist/acorn.js:550:15)
    at Function.parse (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/acorn/dist/acorn.js:572:35)
    at Object.parse (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/acorn/dist/acorn.js:5288:17)
    at globbedFiles.forEach (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/index.js:160:17)
    at Array.forEach (<anonymous>)
    at files.forEach (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/index.js:155:20)
    at Array.forEach (<anonymous>)
    at Command.prog.version.argument.argument.option.option.action [as _action] (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/index.js:144:11)
    at Command._run (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/caporal/lib/command.js:413:40)
    at Program._run (/Users/colch/.npm/_npx/93411/lib/node_modules/es-check/node_modules/caporal/lib/program.js:170:16)

Why Is This Update Needed?

program crashes

Are There Examples Of This Requested Update Elsewhere?

no

Read about references issues here. Provide paragraph text responses to each header.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Replaced the old Node.js version in your .nvmrc with the new one
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Expose a JS API

Requested Update

Expose a JS API so the module can be required and used as a function.

Why Is This Update Needed?

Currently this module is only a CLI tool, but it would be great to use it programatically too.

Are There Examples Of This Requested Update Elsewhere?

n/a

Command failed with exit code 1

es-check fails if no files found. This is not okay in my case, because I have a variable number of bundled js files, including zero.

update acorn version to latest

Requested Update

update acorn version to latest 6 or 7

Why Is This Update Needed?

Vulnerabilities: Regular Expression Denial of Service

Reproduce:

  1. Just run npm audit.

Are There Examples Of This Requested Update Elsewhere?

Nothing

[issue]: terminal pipeline

I run es-check es5 project/**/*.js | grep 'erroring file' multi times in my project

It said:

ES-Check: there were 79 ES version matching errors.
          · erroring file: xxxA.js
          · erroring file: xxxB.js
          · erroring file: xxxC.js

There were always 79 error files in my project, that's ok,
but grep erroring file count seems random, sometimes 63, sometimes 47,
I just can't tell what all those files are.


Also meet this problem while using it in Node (maybe make an incode requirable version as well?)

exec('es-check es5 myFolder', (err, stdout, stderr) => {
    console.log(err)
});

I check your code

I think this issue may be caused by process.exit...
forEach is synchronous but log is not?
So it return before log all the items

and don't use logger.error for everything...
e.g.

logger.error(`ES-Check: there were no ES version matching errors!  🎉`)
// => better
logger.log(`ES-Check: there were no ES version matching errors!  🎉`)

Feature: Your code will run on 95% of all browsers

Requested Update

It would be really cool to be able to test your entire code and then see a small status at the bottom: "Your code will run on 95% of all browsers". If you change one feature it will run on 98%.
The data could be compared to caniuse-lite database to see exactly what features are used by browsers.

Why Is This Update Needed?

Just testing against es6 is not enough, some browsers only have partial support. It would be really useful to have exact statistics of where our code will run and what can we do to make it run on even more browsers without using babel, maybe we are just using one weird feature which we can manually replace ourselves.

Are There Examples Of This Requested Update Elsewhere?

I don't think so.

Read about references issues here. Provide paragraph text responses to each header.

Interpreting the output

I performed the following on my JS directory and got the following response:

What does the error actually mean?
· error: SyntaxError: Invalid number (22:51)

If that is line #, then character in that line, then in my code its point to the last letter of an object key definition...not an a number. Is it a line/char after it has been minified or the line/char from the raw source file?

:\Users\RPO\dev\myap\www\js>es-check --module es6 *.js
S-Check: there were 1 ES version matching errors.

         ES-Check Error:
         ----
         · erroring file: servicesTride.js
         · error: SyntaxError: Invalid number (22:51)
         · see the printed err.stack below for context
         ----

         SyntaxError: Invalid number (22:51)
   at Parser.pp$4.raise (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:2769:13)
   at Parser.pp$8.readNumber (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:4997:36)
   at Parser.pp$8.getTokenFromCode (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:4875:17)
   at Parser.pp$8.readToken (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:4633:15)
   at Parser.pp$8.nextToken (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:4624:15)
   at Parser.pp$8.next (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:4581:8)
   at Parser.pp.eat (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:610:10)
   at Parser.pp$3.parsePropertyValue (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:2475:12)
   at Parser.pp$3.parseProperty (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:2467:8)
   at Parser.pp$3.parseObj (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:2413:23)
   at Parser.pp$3.parseExprAtom (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:2212:17)
   at Parser.pp$3.parseExprSubscripts (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:2074:19)
   at Parser.pp$3.parseMaybeUnary (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:2051:17)
   at Parser.pp$3.parseExprOps (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:1993:19)
   at Parser.pp$3.parseMaybeConditional (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:1976:19)
   at Parser.pp$3.parseMaybeAssign (C:\Users\RPO\AppData\Roaming\npm\node_modules\es-check\node_modules\acorn\dist\acorn.js:1951:19)

Quite mode doesn't work

Passing --quiet flag doesn't do anything. I'm still getting ES-Check: there were no ES version matching errors! 🎉
(I'm getting it on a file that doesn't work in IE11, but that's another issue...)

Make --module,--allow-hash-bang, and `--verbose` flags

Requested Update

If we pass --module, --allow-hash-bang, or --verbose the true value should be implied rather than passed in like it is currently. IE --module true should not be needed, it should just be --module.

Why Is This Update Needed?

Flags are fairly standard for most cli applications, and at first glance it would be tough to understand es-check because these options are flags but you have to pass a true value anyway.

Are There Examples Of This Requested Update Elsewhere?

I think this will have to be fixed upstream before we add it here, unless we want to switch the argument parsing library that we use.
mattallty/Caporal.js#107

Allowing validating ES5 code with module=true

Requested Update

Allow validating code written in ES5 EXCEPT module imports/exports.

Why Is This Update Needed?

We're transpiling our code to ES5 but still use ES modules to allow for tree-shaking.
We wanted to make sure our generated code is ES5 with the exception of the module syntax which will be handled by webpack in consuming projects (talking about an internal lib).

We need to somehow ignore import/export syntax while still ES5-check our code, if possible/makes sense to you guys.

Thanks a bunch!

[feature request] wrapper command for "minimum ES version" for a file

Requested Update

es-check can have a function to tell us the minimum version of all ES versions that allows a file to parse normally.

This can be done by simply testing against all parsers, or by bisection (with es4 singled out of course) in a million years when testing all yearly ES versions becomes uneconomical.

Why Is This Update Needed?

One can use the new feature to determine the approximate compatibility of a piece of code. With #72 in place this would make a great tool for devs.

It can also be used for "dating" a piece of ancient code found in some ancient ruins.

bug

Requested Update

Why Is This Update Needed?

Are There Examples Of This Requested Update Elsewhere?

Read about references issues here. Provide paragraph text responses to each header.

es-check es5 does not catch Promise, Map, Set etc.

Requested Update

I was asked today if there was a tool to check if the transpiled code was ES5 and I referred to this project but I just checked and es-check es5 ... does not catch Promise from ES2015.

Why Is This Update Needed?

The reason I was asked is that they have continuous issues with bug reports because they forget to add polyfills to their projects. They need an automated way to check which polyfills they are missing from their transpiled code.

Are There Examples Of This Requested Update Elsewhere?

An in-range update of conventional-changelog-cli is breaking the build 🚨

The devDependency conventional-changelog-cli was updated from 2.0.5 to 2.0.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

conventional-changelog-cli is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

[Feature request] Entering a wrong ES version should fail

Requested Update

Currently, using es-check foo dist/*.js returns ES-Check: there were no ES version matching errors! 🎉

However you could assume that if the dev mistyped foo instead of es4, he could also mistype se7 instead of es7.
I think es-check should throw an error when it does not recognize a valid ecmaVersion argument (see the default behavior in

switch (v) {
).

Why Is This Update Needed?

Devs that check their ES version do not need to be handled; lets tell them the harsh truth; they made a typo!

Are There Examples Of This Requested Update Elsewhere?

Nope, but issue #40 could have been avoided perhaps?
Specially if when such an error is detected, you could display a usage info with all the possible ecmaVersion.

Update or remove dependency on cycle package

Requested Update

Find a different solution for the cycle package. The package itself is only one file with two (short) functions with a "public domain" license published to NPM in 2014.

Why Is This Update Needed?

It does not provide a valid LICENSE as part of the project causing CI tools to fail due to not parsing the package.json. It also appears to be abandoned by the maintainer based on this issue from 2018.

Are There Examples Of This Requested Update Elsewhere?

It looks like other packages depend on this facing the same issue as I have.

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.