Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
no-implicit-dependencies: strip BOM before parsing JSON (#3362)
Browse files Browse the repository at this point in the history
[no-log]
  • Loading branch information
ajafff authored and adidahiya committed Oct 20, 2017
1 parent fff81e7 commit ecaad8e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rules/noImplicitDependenciesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ function getDependencies(fileName: string, options: Options): Set<string> {
const packageJsonPath = findPackageJson(path.resolve(path.dirname(fileName)));
if (packageJsonPath !== undefined) {
// don't use require here to avoid caching
const content = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")) as PackageJson;
// remove BOM from file content before parsing
const content = JSON.parse(fs.readFileSync(packageJsonPath, "utf8").replace(/^\uFEFF/, "")) as PackageJson;
if (content.dependencies !== undefined) {
addDependencies(result, content.dependencies);
}
Expand Down
5 changes: 5 additions & 0 deletions test/rules/no-implicit-dependencies/default/bom/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "bom",
"version": "1.0.0",
"dependencies": {}
}
2 changes: 2 additions & 0 deletions test/rules/no-implicit-dependencies/default/bom/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as ts from "typescript";
~~~~~~~~~~~~ [Module 'typescript' is not listed as dependency in package.json]
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {assert} from 'chai';
~~~~~~ [err % ('chai')]
import foo from 'foo';

import Foo from 'Foo';
~~~~~ [err % ('Foo')]

if (foo) {
const common = require('common');
~~~~~~~~ [err % ('common')]
Expand Down

0 comments on commit ecaad8e

Please sign in to comment.