diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..5a66979e --- /dev/null +++ b/.eslintrc @@ -0,0 +1,11 @@ +{ + "parser": "babel-eslint", + "rules": { + "comma-dangle": 0, + "quotes": [2, "single", "avoid-escape"], + "strict": 0 + }, + "env": { + "node": true + } +} diff --git a/bin/__tests__/jscodeshift-test.js b/bin/__tests__/jscodeshift-test.js index af22565c..a4918488 100644 --- a/bin/__tests__/jscodeshift-test.js +++ b/bin/__tests__/jscodeshift-test.js @@ -8,14 +8,13 @@ * */ -/*global jest, describe, pit, expect*/ - -'use strict'; +/*global jest, jasmine, describe, pit, expect*/ +/*eslint camelcase: 0, no-unused-vars: 0*/ jest.autoMockOff(); // Increase default timeout (5000ms) for Travis -jasmine.getEnv().defaultTimeoutInterval = 15000; +jasmine.getEnv().defaultTimeoutInterval = 30000; var child_process = require('child_process'); var fs = require('fs'); @@ -57,7 +56,7 @@ describe('jscodeshift CLI', () => { pit('calls the transform and file information', () => { var sourceA = createTempFileWith('a'); - var sourceB = createTempFileWith('b'); + var sourceB = createTempFileWith('b\n'); var sourceC = createTempFileWith('c'); var transformA = createTransformWith( 'return "transform" + fileInfo.source;' @@ -70,7 +69,7 @@ describe('jscodeshift CLI', () => { run(['--no-extensions', '-t', transformA, sourceA, sourceB]).then( ([stdout, stderr]) => { expect(fs.readFileSync(sourceA).toString()).toBe('transforma'); - expect(fs.readFileSync(sourceB).toString()).toBe('transformb'); + expect(fs.readFileSync(sourceB).toString()).toBe('transformb\n'); } ), run(['--no-extensions', '-t', transformB, sourceC]).then( diff --git a/src/__tests__/core-test.js b/src/__tests__/core-test.js index b5770dd8..54274121 100644 --- a/src/__tests__/core-test.js +++ b/src/__tests__/core-test.js @@ -8,10 +8,10 @@ * */ -'use strict'; +/*global jest, describe, it, expect*/ + jest.autoMockOff(); var core = require('../core'); -var Collection = require('../Collection'); var recast = require('recast'); var b = recast.types.builders; var NodePath = recast.types.NodePath; @@ -46,8 +46,13 @@ describe('core API', function() { }); it('throws if it gets an invalid value', function() { - expect(_ => core(42)).toThrow(); - expect(_ => core({})).toThrow(); + expect(() => core(42)).toThrow(); + expect(() => core({})).toThrow(); + }); + + it('returns the source as is if nothing was modified', function () { + var source = '\nvar foo;\n'; + expect(core(source).toSource()).toEqual(source); }); }); diff --git a/src/core.js b/src/core.js index 61250984..90799c41 100644 --- a/src/core.js +++ b/src/core.js @@ -71,7 +71,7 @@ function fromAST(ast) { } function fromSource(source) { - return fromAST(recast.parse(source, {esprima: babel}).program); + return fromAST(recast.parse(source, {esprima: babel})); } /**