Skip to content

Commit 565f3d3

Browse files
feat: show filename on formatting error
1 parent 63db7d9 commit 565f3d3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ module.exports = function(options) {
3636

3737
this.push(file);
3838
} catch (error) {
39-
this.emit('error', new PluginError(PLUGIN_NAME, error));
39+
this.emit(
40+
'error',
41+
new PluginError(PLUGIN_NAME, error, { fileName: file.path })
42+
);
4043
}
4144

4245
callback();
@@ -79,7 +82,10 @@ module.exports.check = function(options) {
7982

8083
this.push(file);
8184
} catch (error) {
82-
this.emit('error', new PluginError(PLUGIN_NAME, error));
85+
this.emit(
86+
'error',
87+
new PluginError(PLUGIN_NAME, error, { fileName: file.path })
88+
);
8389
}
8490

8591
callback();

test/index.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ describe('gulp-prettier', () => {
114114
assert.ok(err instanceof PluginError);
115115
assert.strictEqual(err.plugin, pkg.name);
116116
assert.strictEqual(err.name, 'SyntaxError');
117+
assert.strictEqual(
118+
err.fileName,
119+
path.join(process.cwd(), 'src', 'error.js')
120+
);
117121
done();
118122
});
119123

0 commit comments

Comments
 (0)