Skip to content

Commit 194b219

Browse files
committed
chore(global): use two-space indenting and single quotes (closes #45)
1 parent 62c15b5 commit 194b219

File tree

9 files changed

+433
-427
lines changed

9 files changed

+433
-427
lines changed

.editorconfig

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
# http://editorconfig.org
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
25
root = true
36

47
[*]
5-
indent_style = tab
6-
indent_size = 4
8+
9+
# Change these settings to your own preference
10+
indent_style = space
11+
indent_size = 2
12+
13+
# We recommend you to keep these unchanged
714
end_of_line = lf
815
charset = utf-8
916
trim_trailing_whitespace = true
@@ -12,10 +19,6 @@ insert_final_newline = true
1219
[*.md]
1320
trim_trailing_whitespace = false
1421

15-
[*.{json,yml}]
16-
indent_style = space
17-
indent_size = 2
18-
1922
[test/fixtures/*]
2023
insert_final_newline = false
2124
trim_trailing_whitespace = false

.jshintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"curly": true,
77
"eqeqeq": true,
88
"immed": true,
9-
"indent": 4,
9+
"indent": 2,
1010
"latedef": true,
1111
"newcap": true,
1212
"noarg": true,
13-
"quotmark": "double",
13+
"quotmark": "single",
1414
"regexp": true,
1515
"undef": true,
1616
"unused": true,

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ var rename = require("gulp-rename");
1616

1717
// rename via string
1818
gulp.src("./src/main/text/hello.txt")
19-
.pipe(rename("main/text/ciao/goodbye.md"))
20-
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/goodbye.md
19+
.pipe(rename("main/text/ciao/goodbye.md"))
20+
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/goodbye.md
2121

2222
// rename via function
2323
gulp.src("./src/**/hello.txt")
24-
.pipe(rename(function (path) {
25-
path.dirname += "/ciao";
26-
path.basename += "-goodbye";
27-
path.extname = ".md"
28-
}))
29-
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md
24+
.pipe(rename(function (path) {
25+
path.dirname += "/ciao";
26+
path.basename += "-goodbye";
27+
path.extname = ".md"
28+
}))
29+
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md
3030

3131
// rename via hash
3232
gulp.src("./src/main/text/hello.txt", { base: process.cwd() })
33-
.pipe(rename({
34-
dirname: "main/text/ciao",
35-
basename: "aloha",
36-
prefix: "bonjour-",
37-
suffix: "-hola",
38-
extname: ".md"
39-
}))
40-
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/bonjour-aloha-hola.md
33+
.pipe(rename({
34+
dirname: "main/text/ciao",
35+
basename: "aloha",
36+
prefix: "bonjour-",
37+
suffix: "-hola",
38+
extname: ".md"
39+
}))
40+
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/bonjour-aloha-hola.md
4141
```
4242

4343
**See test/rename.spec.js for more examples and test/path-parsing.spec.js for hairy details.**

index.js

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,65 @@
1-
var Stream = require("stream"),
2-
Path = require("path");
1+
'use strict';
2+
3+
var Stream = require('stream');
4+
var Path = require('path');
35

46
function gulpRename(obj) {
5-
"use strict";
67

7-
var stream = new Stream.Transform({objectMode: true});
8+
var stream = new Stream.Transform({objectMode: true});
9+
10+
function parsePath(path) {
11+
var extname = Path.extname(path);
12+
return {
13+
dirname: Path.dirname(path),
14+
basename: Path.basename(path, extname),
15+
extname: extname
16+
};
17+
}
18+
19+
stream._transform = function(file, unused, callback) {
820

9-
function parsePath(path) {
10-
var extname = Path.extname(path);
11-
return {
12-
dirname: Path.dirname(path),
13-
basename: Path.basename(path, extname),
14-
extname: extname
15-
};
16-
}
21+
var parsedPath = parsePath(file.relative);
22+
var path;
1723

18-
stream._transform = function(file, unused, callback) {
24+
var type = typeof obj;
1925

20-
var parsedPath = parsePath(file.relative);
21-
var path;
26+
if (type === 'string' && obj !== '') {
2227

23-
var type = typeof obj;
28+
path = obj;
2429

25-
if (type === "string" && obj !== "") {
30+
} else if (type === 'function') {
2631

27-
path = obj;
32+
obj(parsedPath);
33+
path = Path.join(parsedPath.dirname, parsedPath.basename + parsedPath.extname);
2834

29-
} else if (type === "function") {
35+
} else if (type === 'object' && obj !== undefined && obj !== null) {
3036

31-
obj(parsedPath);
32-
path = Path.join(parsedPath.dirname, parsedPath.basename + parsedPath.extname);
37+
var dirname = 'dirname' in obj ? obj.dirname : parsedPath.dirname,
38+
prefix = obj.prefix || '',
39+
suffix = obj.suffix || '',
40+
basename = 'basename' in obj ? obj.basename : parsedPath.basename,
41+
extname = 'extname' in obj ? obj.extname : parsedPath.extname;
3342

34-
} else if (type === "object" && obj !== undefined && obj !== null) {
43+
path = Path.join(dirname, prefix + basename + suffix + extname);
3544

36-
var dirname = "dirname" in obj ? obj.dirname : parsedPath.dirname,
37-
prefix = obj.prefix || "",
38-
suffix = obj.suffix || "",
39-
basename = "basename" in obj ? obj.basename : parsedPath.basename,
40-
extname = "extname" in obj ? obj.extname : parsedPath.extname;
45+
} else {
4146

42-
path = Path.join(dirname, prefix + basename + suffix + extname);
47+
callback(new Error('Unsupported renaming parameter type supplied'), undefined);
48+
return;
4349

44-
} else {
45-
callback(new Error("Unsupported renaming parameter type supplied"), undefined);
46-
return;
47-
}
50+
}
4851

49-
file.path = Path.join(file.base, path);
52+
file.path = Path.join(file.base, path);
5053

51-
// Rename sourcemap if present
52-
if (file.sourceMap) {
53-
file.sourceMap.file = file.relative;
54-
}
54+
// Rename sourcemap if present
55+
if (file.sourceMap) {
56+
file.sourceMap.file = file.relative;
57+
}
5558

56-
callback(null, file);
57-
};
59+
callback(null, file);
60+
};
5861

59-
return stream;
62+
return stream;
6063
}
6164

6265
module.exports = gulpRename;

test/.jshintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"extends": "../.jshintrc",
3-
"mocha": true
2+
"extends": "../.jshintrc",
3+
"mocha": true
44
}

0 commit comments

Comments
 (0)