Skip to content

Commit

Permalink
Use eslint, nyc (#321)
Browse files Browse the repository at this point in the history
* Use eslint and nyc

* migrate to jest

* Use ava

* fix prefer-const
  • Loading branch information
danez committed Oct 30, 2016
1 parent 19052e4 commit 4eace42
Show file tree
Hide file tree
Showing 22 changed files with 611 additions and 659 deletions.
9 changes: 8 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"presets": [
["latest", { "es2015": { "loose": true } }]
]
],
"env": {
"test": {
"plugins": [
"istanbul"
]
}
}
}
3 changes: 2 additions & 1 deletion .jshintignore → .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lib
test/fixtures
node_modules
test/output
test/fixtures
12 changes: 12 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"es6": true,
"node": true
},
"extends": [
"eslint-config-babel"
],
"rules": {
"prefer-const": "error"
}
}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.nyc_output
coverage
lib
node_modules
npm-debug.log
test/output
coverage
*.log
yarn.lock
10 changes: 0 additions & 10 deletions .jscsrc

This file was deleted.

5 changes: 0 additions & 5 deletions .jshintrc

This file was deleted.

9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ node_js:
- "0.12"
matrix:
include:
- node_js: "6"
- node_js: "lts/*"
env: WEBPACK_VERSION="1"
- node_js: "lts/*"
env: LINT=true
- node_js: "0.10"
env: WEBPACK_VERSION="1"
before_script:
- 'if [ "$WEBPACK_VERSION" ]; then npm install webpack@$WEBPACK_VERSION; fi'
script:
- npm run travis
- 'if [ -n "${LINT-}" ]; then npm run lint ; fi'
- 'if [ -z "${LINT-}" ]; then npm run test-ci ; fi'
after_success:
- bash <(curl -s https://codecov.io/bash)
- npm run coverage
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage:
parsers:
javascript:
enable_partials: yes
49 changes: 35 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,32 @@
"webpack": "1 || ^2.1.0-beta"
},
"devDependencies": {
"ava": "^0.16.0",
"babel-cli": "^6.18.0",
"babel-core": "^6.0.0",
"babel-preset-latest": "^6.16.0",
"babel-eslint": "^7.1.0",
"babel-plugin-istanbul": "^2.0.3",
"babel-preset-es2015": "^6.0.0",
"expect.js": "^0.3.1",
"istanbul": "^0.4.0",
"jscs": "^3.0.7",
"jshint": "^2.8.0",
"mocha": "^3.0.2",
"babel-preset-latest": "^6.16.0",
"codecov": "^1.0.1",
"cross-env": "^2.0.0",
"eslint": "^3.8.1",
"eslint-config-babel": "^2.0.1",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-flowtype": "^2.25.0",
"nyc": "^8.3.2",
"rimraf": "^2.4.3",
"webpack": "2.1.0-beta.22"
},
"scripts": {
"build": "babel src/ --out-dir lib/",
"test": "npm run build && npm run hint && npm run cs && npm run cover",
"travis": "npm run build && npm run cover -- --report lcovonly",
"cover": "istanbul cover ./node_modules/.bin/_mocha -- test/*.test.js",
"postcover": "npm run hint && npm run cs",
"coverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
"lint": "eslint src test",
"preversion": "npm test",
"prepublish": "npm run build",
"hint": "jshint --config .jshintrc src/* test/*",
"cs": "jscs --config .jscsrc src/* test/*"
"test": "npm run lint && npm run build && npm run test-only",
"test-ci": "cross-env BABEL_ENV=test npm run build && nyc npm run test-only",
"test-only": "ava"
},
"repository": {
"type": "git",
Expand All @@ -46,7 +51,6 @@
"keywords": [
"webpack",
"loader",
"6to5",
"babel",
"es6",
"transpiler",
Expand All @@ -57,5 +61,22 @@
"bugs": {
"url": "https://github.com/babel/babel-loader/issues"
},
"homepage": "https://github.com/babel/babel-loader"
"homepage": "https://github.com/babel/babel-loader",
"nyc": {
"all": true,
"include": [
"src/**/*.js"
],
"sourceMap": false,
"instrument": false
},
"ava": {
"files": [
"test/**/*.test.js"
],
"source": [
"src/**/*.test.js"
],
"babel": "inherit"
}
}
50 changes: 25 additions & 25 deletions src/fs-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
* @see https://github.com/babel/babel-loader/issues/34
* @see https://github.com/babel/babel-loader/pull/41
*/
var crypto = require('crypto');
var mkdirp = require('mkdirp');
var findCacheDir = require('find-cache-dir');
var fs = require('fs');
var os = require('os');
var path = require('path');
var zlib = require('zlib');
const crypto = require("crypto");
const mkdirp = require("mkdirp");
const findCacheDir = require("find-cache-dir");
const fs = require("fs");
const os = require("os");
const path = require("path");
const zlib = require("zlib");

/**
* Read the contents from the compressed file.
Expand All @@ -22,12 +22,12 @@ var zlib = require('zlib');
* @params {String} filename
* @params {Function} callback
*/
var read = function(filename, callback) {
const read = function(filename, callback) {
return fs.readFile(filename, function(err, data) {
if (err) { return callback(err); }

return zlib.gunzip(data, function(err, content) {
var result = {};
let result = {};

if (err) { return callback(err); }

Expand All @@ -51,8 +51,8 @@ var read = function(filename, callback) {
* @params {String} result
* @params {Function} callback
*/
var write = function(filename, result, callback) {
var content = JSON.stringify(result);
const write = function(filename, result, callback) {
const content = JSON.stringify(result);

return zlib.gzip(content, function(err, data) {
if (err) { return callback(err); }
Expand All @@ -70,17 +70,17 @@ var write = function(filename, result, callback) {
*
* @return {String}
*/
var filename = function(source, identifier, options) {
var hash = crypto.createHash('SHA1');
var contents = JSON.stringify({
const filename = function(source, identifier, options) {
const hash = crypto.createHash("SHA1");
const contents = JSON.stringify({
source: source,
options: options,
identifier: identifier,
});

hash.end(contents);

return hash.read().toString('hex') + '.json.gzip';
return hash.read().toString("hex") + ".json.gzip";
};

/**
Expand Down Expand Up @@ -116,29 +116,29 @@ var filename = function(source, identifier, options) {
*
* });
*/
var cache = module.exports = function(params, callback) {
module.exports = function(params, callback) {
// Spread params into named variables
// Forgive user whenever possible
var source = params.source;
var options = params.options || {};
var transform = params.transform;
var identifier = params.identifier;
var directory;
const source = params.source;
const options = params.options || {};
const transform = params.transform;
const identifier = params.identifier;
let directory;

if (typeof params.directory === 'string') {
if (typeof params.directory === "string") {
directory = params.directory;
} else {
directory = findCacheDir({ name: 'babel-loader' }) || os.tmpdir();
directory = findCacheDir({ name: "babel-loader" }) || os.tmpdir();
}

var file = path.join(directory, filename(source, identifier, options));
const file = path.join(directory, filename(source, identifier, options));

// Make sure the directory exists.
return mkdirp(directory, function(err) {
if (err) { return callback(err); }

return read(file, function(err, content) {
var result = {};
let result = {};
// No errors mean that the file was previously cached
// we just need to return it
if (!err) { return callback(null, content); }
Expand Down
Loading

0 comments on commit 4eace42

Please sign in to comment.