Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: strip Unicode BOM of config files (fixes #6556) (#6580)
  • Loading branch information
mysticatea authored and nzakas committed Jul 4, 2016
1 parent ee7fcfa commit 6ef2cbe
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/config/config-file.js
Expand Up @@ -20,6 +20,7 @@ var debug = require("debug"),
pathUtil = require("../util/path-util"),
ModuleResolver = require("../util/module-resolver"),
pathIsInside = require("path-is-inside"),
stripBom = require("strip-bom"),
stripComments = require("strip-json-comments"),
stringify = require("json-stable-stringify"),
isAbsolutePath = require("path-is-absolute"),
Expand Down Expand Up @@ -68,7 +69,7 @@ debug = debug("eslint:config-file");
* @private
*/
function readFile(filePath) {
return fs.readFileSync(filePath, "utf8");
return stripBom(fs.readFileSync(filePath, "utf8"));
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -65,6 +65,7 @@
"progress": "^1.1.8",
"require-uncached": "^1.0.2",
"shelljs": "^0.6.0",
"strip-bom": "^3.0.0",
"strip-json-comments": "~1.0.1",
"table": "^3.7.8",
"text-table": "~0.2.0",
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/config-file/bom/.eslintrc.json
@@ -0,0 +1,5 @@
{
"rules": {
"semi": "error"
}
}
2 changes: 2 additions & 0 deletions tests/fixtures/config-file/bom/.eslintrc.yaml
@@ -0,0 +1,2 @@
rules:
semi: error
10 changes: 10 additions & 0 deletions tests/fixtures/config-file/bom/package.json
@@ -0,0 +1,10 @@
{
"private": true,
"name": "eslint-test",
"version": "0.0.0",
"eslintConfig": {
"rules": {
"semi": "error"
}
}
}
40 changes: 40 additions & 0 deletions tests/lib/config/config-file.js
Expand Up @@ -760,6 +760,46 @@ describe("ConfigFile", function() {
});
});

describe("even if config files have Unicode BOM,", function() {
it("should read the JSON config file correctly.", function() {
var config = ConfigFile.load(getFixturePath("bom/.eslintrc.json"));

assert.deepEqual(config, {
env: {},
globals: {},
parserOptions: {},
rules: {
semi: "error"
}
});
});

it("should read the YAML config file correctly.", function() {
var config = ConfigFile.load(getFixturePath("bom/.eslintrc.yaml"));

assert.deepEqual(config, {
env: {},
globals: {},
parserOptions: {},
rules: {
semi: "error"
}
});
});

it("should read the config in package.json correctly.", function() {
var config = ConfigFile.load(getFixturePath("bom/package.json"));

assert.deepEqual(config, {
env: {},
globals: {},
parserOptions: {},
rules: {
semi: "error"
}
});
});
});
});

describe("resolve()", function() {
Expand Down

0 comments on commit 6ef2cbe

Please sign in to comment.