mirror of
https://github.com/zhigang1992/replace-in-file.git
synced 2026-01-12 17:43:32 +08:00
Update dependencies, use ESLint, fix line length issues
This commit is contained in:
@@ -10,8 +10,8 @@ indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# JS/JSON
|
||||
[{*.js,*.json}]
|
||||
# JS
|
||||
[{*.js}]
|
||||
quote_type = single
|
||||
curly_bracket_next_line = false
|
||||
spaces_around_operators = true
|
||||
|
||||
138
.eslintrc.yaml
Normal file
138
.eslintrc.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
root: true
|
||||
extends: eslint:recommended
|
||||
parserOptions:
|
||||
ecmaVersion: 6
|
||||
ecmaFeatures:
|
||||
impliedStrict: true
|
||||
sourceType: module
|
||||
env:
|
||||
es6: true
|
||||
node: true
|
||||
mocha: true
|
||||
jasmine: true
|
||||
rules:
|
||||
linebreak-style:
|
||||
- error
|
||||
- unix
|
||||
max-len:
|
||||
- warn
|
||||
- code: 80
|
||||
tabWidth: 2
|
||||
indent:
|
||||
- error
|
||||
- 2
|
||||
- SwitchCase: 1
|
||||
VariableDeclarator:
|
||||
let: 2
|
||||
const: 3
|
||||
semi:
|
||||
- error
|
||||
- always
|
||||
consistent-this:
|
||||
- error
|
||||
- self
|
||||
- $ctrl
|
||||
quotes:
|
||||
- error
|
||||
- single
|
||||
- allowTemplateLiterals: true
|
||||
curly:
|
||||
- error
|
||||
- all
|
||||
comma-dangle:
|
||||
- error
|
||||
- always-multiline
|
||||
new-cap:
|
||||
- error
|
||||
- newIsCap: true
|
||||
capIsNew: true
|
||||
properties: false
|
||||
camelcase:
|
||||
- error
|
||||
- properties: never
|
||||
array-bracket-spacing:
|
||||
- error
|
||||
- never
|
||||
arrow-spacing:
|
||||
- error
|
||||
- before: true
|
||||
after: true
|
||||
block-spacing:
|
||||
- error
|
||||
- always
|
||||
comma-spacing:
|
||||
- error
|
||||
- before: false
|
||||
after: true
|
||||
computed-property-spacing:
|
||||
- error
|
||||
- never
|
||||
generator-star-spacing:
|
||||
- error
|
||||
- before: true
|
||||
after: false
|
||||
key-spacing:
|
||||
- error
|
||||
- beforeColon: false
|
||||
afterColon: true
|
||||
mode: minimum
|
||||
keyword-spacing:
|
||||
- error
|
||||
- before: true
|
||||
semi-spacing:
|
||||
- error
|
||||
- before: false
|
||||
after: true
|
||||
space-in-parens:
|
||||
- error
|
||||
- never
|
||||
space-unary-ops:
|
||||
- error
|
||||
- words: true
|
||||
nonwords: false
|
||||
space-before-function-paren:
|
||||
- error
|
||||
- never
|
||||
space-before-blocks:
|
||||
- error
|
||||
- always
|
||||
yoda:
|
||||
- error
|
||||
- never
|
||||
wrap-iife:
|
||||
- error
|
||||
- outside
|
||||
eqeqeq:
|
||||
- error
|
||||
- always
|
||||
newline-per-chained-call:
|
||||
- error
|
||||
- ignoreChainWithDepth: 3
|
||||
one-var-declaration-per-line:
|
||||
- error
|
||||
- initializations
|
||||
brace-style:
|
||||
- error
|
||||
- stroustrup
|
||||
no-implicit-coercion:
|
||||
- error
|
||||
- boolean: false
|
||||
no-multiple-empty-lines:
|
||||
- error
|
||||
- max: 1
|
||||
eol-last: error
|
||||
dot-notation: error
|
||||
space-infix-ops: error
|
||||
no-with: error
|
||||
no-unreachable: error
|
||||
no-redeclare: error
|
||||
no-unexpected-multiline: error
|
||||
no-multi-spaces: error
|
||||
no-multi-str: error
|
||||
no-trailing-spaces: error
|
||||
no-mixed-spaces-and-tabs: error
|
||||
no-spaced-func: error
|
||||
no-whitespace-before-property: error
|
||||
no-lonely-if: error
|
||||
no-var: error
|
||||
no-console: off
|
||||
21
.jscsrc
21
.jscsrc
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"preset": "google",
|
||||
"fileExtensions": [".js"],
|
||||
"maxErrors": 100,
|
||||
"excludeFiles": [
|
||||
"node_modules/**",
|
||||
"coverage/**"
|
||||
],
|
||||
"requireParenthesesAroundIIFE": true,
|
||||
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
|
||||
"maximumLineLength": 100,
|
||||
"validateLineBreaks": "LF",
|
||||
"validateIndentation": 2,
|
||||
"disallowTrailingComma": true,
|
||||
"disallowMultipleSpaces": true,
|
||||
"disallowMultipleVarDecl": "exceptUndefined",
|
||||
"disallowKeywordsOnNewLine": null,
|
||||
"disallowSpacesInsideObjectBrackets": null,
|
||||
"disallowImplicitTypeConversion": ["string"],
|
||||
"safeContextKeyword": "self"
|
||||
}
|
||||
34
.jshintrc
34
.jshintrc
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"bitwise": false,
|
||||
"curly": true,
|
||||
"devel": true,
|
||||
"esnext": true,
|
||||
"eqeqeq": true,
|
||||
"forin": true,
|
||||
"funcscope": true,
|
||||
"futurehostile": true,
|
||||
"globals": {
|
||||
"define": false,
|
||||
"require": false,
|
||||
"exports": false,
|
||||
"module": false,
|
||||
"describe": false,
|
||||
"before": false,
|
||||
"beforeEach": false,
|
||||
"after": false,
|
||||
"afterEach": false,
|
||||
"it": false,
|
||||
"inject": false,
|
||||
"expect": false,
|
||||
"Promise": true
|
||||
},
|
||||
"latedef": "nofunc",
|
||||
"noarg": true,
|
||||
"nonew": true,
|
||||
"notypeof": true,
|
||||
"strict": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"browser": false,
|
||||
"node": true
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
var fs = require('fs');
|
||||
let fs = require('fs');
|
||||
|
||||
/**
|
||||
* Helper to replace in a single file
|
||||
@@ -15,7 +15,7 @@ function replace(filePath, find, replace, cb) {
|
||||
}
|
||||
|
||||
//Replace contents and check if anything changed
|
||||
var newContents = contents.replace(find, replace);
|
||||
let newContents = contents.replace(find, replace);
|
||||
if (newContents === contents) {
|
||||
return cb(null, false);
|
||||
}
|
||||
@@ -36,10 +36,10 @@ function replace(filePath, find, replace, cb) {
|
||||
function replaceSync(filePath, find, replace) {
|
||||
|
||||
//Read contents
|
||||
var contents = fs.readFileSync(filePath, 'utf8');
|
||||
let contents = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
//Replace contents and check if anything changed
|
||||
var newContents = contents.replace(find, replace);
|
||||
let newContents = contents.replace(find, replace);
|
||||
if (newContents === contents) {
|
||||
return false;
|
||||
}
|
||||
@@ -60,9 +60,9 @@ module.exports = function replaceInFile(config, cb) {
|
||||
}
|
||||
|
||||
//Initialize helper vars
|
||||
var totalFiles = config.files.length;
|
||||
var processedFiles = 0;
|
||||
var changedFiles = [];
|
||||
let totalFiles = config.files.length;
|
||||
let processedFiles = 0;
|
||||
let changedFiles = [];
|
||||
|
||||
//No callback given? Perform sync operation
|
||||
if (!cb) {
|
||||
|
||||
17
package.json
17
package.json
@@ -24,9 +24,7 @@
|
||||
],
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "npm run lint:jshint -s && npm run lint:jscs -s",
|
||||
"lint:jshint": "jshint . --reporter=node_modules/jshint-stylish",
|
||||
"lint:jscs": "jscs . --reporter=node_modules/jscs-stylish",
|
||||
"lint": "eslint . --fix",
|
||||
"pretest": "npm run lint -s",
|
||||
"istanbul": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha test/**/*.spec.js",
|
||||
"test": "npm run istanbul -s",
|
||||
@@ -35,17 +33,14 @@
|
||||
"coverage": "open -a \"Google Chrome\" ./coverage/lcov-report/index.html"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.9.0",
|
||||
"babel-preset-es2015": "^6.9.0",
|
||||
"bluebird": "^3.4.0",
|
||||
"babel-cli": "^6.11.4",
|
||||
"babel-preset-es2015": "^6.13.2",
|
||||
"bluebird": "^3.4.1",
|
||||
"chai": "^3.5.0",
|
||||
"chai-as-promised": "^5.3.0",
|
||||
"dirty-chai": "^1.2.2",
|
||||
"eslint": "^3.2.2",
|
||||
"istanbul": "^1.0.0-alpha.2",
|
||||
"jscs": "^3.0.0",
|
||||
"jscs-stylish": "^0.3.1",
|
||||
"jshint": "^2.9.2",
|
||||
"jshint-stylish": "^2.2.0",
|
||||
"mocha": "^2.5.3"
|
||||
"mocha": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('Replace in file', () => {
|
||||
beforeEach(() => Promise.all([
|
||||
writeFile('test1', testData, 'utf8'),
|
||||
writeFile('test2', testData, 'utf8'),
|
||||
writeFile('test3', 'nope', 'utf8')
|
||||
writeFile('test3', 'nope', 'utf8'),
|
||||
]));
|
||||
|
||||
/**
|
||||
@@ -31,7 +31,7 @@ describe('Replace in file', () => {
|
||||
afterEach(() => Promise.all([
|
||||
deleteFile('test1'),
|
||||
deleteFile('test2'),
|
||||
deleteFile('test3')
|
||||
deleteFile('test3'),
|
||||
]));
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: 'test1',
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
}, () => {
|
||||
let test1 = fs.readFileSync('test1', 'utf8');
|
||||
let test2 = fs.readFileSync('test2', 'utf8');
|
||||
@@ -60,7 +60,7 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: 'test1',
|
||||
replace: 're place',
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
}, () => {
|
||||
let test1 = fs.readFileSync('test1', 'utf8');
|
||||
expect(test1).to.equal('a b c');
|
||||
@@ -72,7 +72,7 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: ['test1', 'test2'],
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
}, () => {
|
||||
let test1 = fs.readFileSync('test1', 'utf8');
|
||||
let test2 = fs.readFileSync('test2', 'utf8');
|
||||
@@ -86,7 +86,7 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: 'test1',
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
}, (error) => {
|
||||
expect(error).to.equal(null);
|
||||
done();
|
||||
@@ -97,7 +97,7 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: 'nope',
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
}, (error) => {
|
||||
expect(error).not.to.equal(null);
|
||||
done();
|
||||
@@ -108,18 +108,18 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: 'test1',
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
}, (error, changedFiles) => {
|
||||
expect(changedFiles).to.be.instanceof(Array);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return in changed files if something was replaced', function(done) {
|
||||
it('should return in files if something was replaced', function(done) {
|
||||
replace({
|
||||
files: 'test1',
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
}, (error, changedFiles) => {
|
||||
expect(changedFiles).to.have.length(1);
|
||||
expect(changedFiles[0]).to.equal('test1');
|
||||
@@ -127,11 +127,11 @@ describe('Replace in file', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not return in changed files if nothing replaced', function(done) {
|
||||
it('should not return in files if nothing replaced', function(done) {
|
||||
replace({
|
||||
files: 'test1',
|
||||
replace: 'nope',
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
}, (error, changedFiles) => {
|
||||
expect(changedFiles).to.have.length(0);
|
||||
done();
|
||||
@@ -142,7 +142,7 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: ['test1', 'test2', 'test3'],
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
}, (error, changedFiles) => {
|
||||
expect(changedFiles).to.have.length(2);
|
||||
expect(changedFiles).to.contain('test1');
|
||||
@@ -164,7 +164,7 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: 'test1',
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
});
|
||||
let test1 = fs.readFileSync('test1', 'utf8');
|
||||
let test2 = fs.readFileSync('test2', 'utf8');
|
||||
@@ -176,7 +176,7 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: 'test1',
|
||||
replace: 're place',
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
});
|
||||
let test1 = fs.readFileSync('test1', 'utf8');
|
||||
expect(test1).to.equal('a b c');
|
||||
@@ -186,7 +186,7 @@ describe('Replace in file', () => {
|
||||
replace({
|
||||
files: ['test1', 'test2'],
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
});
|
||||
let test1 = fs.readFileSync('test1', 'utf8');
|
||||
let test2 = fs.readFileSync('test2', 'utf8');
|
||||
@@ -198,7 +198,7 @@ describe('Replace in file', () => {
|
||||
let changedFiles = replace({
|
||||
files: 'test1',
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
});
|
||||
expect(changedFiles).to.be.instanceof(Array);
|
||||
});
|
||||
@@ -207,7 +207,7 @@ describe('Replace in file', () => {
|
||||
let changedFiles = replace({
|
||||
files: 'test1',
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
});
|
||||
expect(changedFiles).to.have.length(1);
|
||||
expect(changedFiles[0]).to.equal('test1');
|
||||
@@ -217,7 +217,7 @@ describe('Replace in file', () => {
|
||||
let changedFiles = replace({
|
||||
files: 'test1',
|
||||
replace: 'nope',
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
});
|
||||
expect(changedFiles).to.have.length(0);
|
||||
});
|
||||
@@ -226,7 +226,7 @@ describe('Replace in file', () => {
|
||||
let changedFiles = replace({
|
||||
files: ['test1', 'test2', 'test3'],
|
||||
replace: /re\splace/g,
|
||||
with: 'b'
|
||||
with: 'b',
|
||||
});
|
||||
expect(changedFiles).to.have.length(2);
|
||||
expect(changedFiles).to.contain('test1');
|
||||
|
||||
Reference in New Issue
Block a user