Skip to content

Commit

Permalink
Add support for jsonc/json with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Kowalski committed Jul 25, 2024
1 parent a3968df commit 8af61e0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion documentation/project-structure-independent-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ If you have any questions **[click here](https://github.com/Igorkowalski94/eslin
├── 📁 components Private / Public for ComplexComponent family.
├── 📄 complexComponent.api.ts Private / Public for ComplexComponent family.
├── 📄 complexComponent.types.ts Private / Public for ComplexComponent family.
└── 📄 ComplexComponent.tsx Private / Public for Feature2 family / Public for SimpleComponent.tsx.
└── 📄 ComplexComponent.tsx Private / Public for ComplexComponent family / Public for Feature2 family / Public for SimpleComponent.tsx.
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Igor Kowalski (Igorkowalski94)",
"name": "eslint-plugin-project-structure",
"version": "2.0.10",
"version": "2.0.11",
"license": "MIT",
"description": "Eslint plugin with rules that will help you achieve a project structure that is scalable, consistent, and well thought out.",
"keywords": [
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/readConfigFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jest.mock("js-yaml", () => ({
describe("readConfigFile", () => {
it("should return config from yaml", () => {
(readFileSync as jest.Mock).mockReturnValue('{"name":"yaml"}');
expect(readConfigFile("folderStructure.yaml")).toEqual({
name: "yaml",
});
expect(readConfigFile("folderStructure.yaml")).toEqual(
'{"name":"yaml"}',
);
});

it("should return undefined when yaml config path is incorrect", () => {
Expand All @@ -32,9 +32,9 @@ describe("readConfigFile", () => {
(load as jest.Mock).mockReturnValue(null);
(readFileSync as jest.Mock).mockReturnValue('{"name":"json"}');

expect(readConfigFile("folderStructure.json")).toEqual({
name: "json",
});
expect(readConfigFile("folderStructure.json")).toEqual(
'{"name":"json"}',
);
});

it("should return undefined when json config path is incorrect", () => {
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/readConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export const readConfigFile = <T>(configPath: string): T | undefined => {
try {
config = load(readFileSync(configPath, "utf8"));

if (!config) config = JSON.parse(readFileSync(configPath, "utf-8"));
if (!config)
config = JSON.parse(
JSON.stringify(readFileSync(configPath, "utf-8")),
);
} catch (error) {
return;
}
Expand Down

0 comments on commit 8af61e0

Please sign in to comment.