jwarby / i18n-lint

`i18n-lint` is a tool for detecting possible hardcoded strings in HTML and HTML-based template source files. It can be used a CLI utility, a library or a Grunt plugin.
http://jwarby.github.io/i18n-lint/
MIT License
50 stars 20 forks source link

The reporter from example provided returns an error #8

Closed cmajsmith closed 5 years ago

cmajsmith commented 6 years ago

Creating the custom reporter as provided in the example here: http://jwarby.github.io/i18n-lint/#usage (under Reporters) results into the error below (node v8.9.4):

$ i18n-lint -r i18_reporter.js -t '{{,}}' app/views/product/*.html
net.js:701
    throw new TypeError(
    ^

TypeError: Invalid data, chunk must be a string or buffer, not object
    at WriteStream.Socket.write (net.js:701:11)
    at /usr/local/lib/node_modules/i18n-lint/bin/i18n-lint:191:26
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/i18n-lint/bin/i18n-lint:170:11
    at f (/usr/local/lib/node_modules/i18n-lint/node_modules/once/once.js:25:25)
    at Glob.<anonymous> (/usr/local/lib/node_modules/i18n-lint/node_modules/glob/glob.js:133:7)
    at emitOne (events.js:116:13)
    at Glob.emit (events.js:211:7)
    at Glob._finish (/usr/local/lib/node_modules/i18n-lint/node_modules/glob/glob.js:172:8)
    at done (/usr/local/lib/node_modules/i18n-lint/node_modules/glob/glob.js:159:12)

In my case the solution was changing the code to:

module.exports = function(errors) {
    var len = errors.length,
        filename;

    if (len) {
        filename = errors[0].file;
        process.stdout.write(filename + '\n -- ' + len + ' hardcoded string(s)\n');
    }
};

I can create a pull-request with the fix to docs if needed.

jwarby commented 6 years ago

Whoops, good catch @CmajSmith. I'd happily accept a pull request for this :+1: