Skip to content

Commit

Permalink
Add prettier and precommit hook (smikula#93)
Browse files Browse the repository at this point in the history
This also runs prettier across the repo so everything is consistent.
  • Loading branch information
smikula authored May 6, 2021
1 parent d1c2711 commit 47f75d2
Show file tree
Hide file tree
Showing 17 changed files with 256 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/
node_modules/
*.md
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"printWidth": 100,
"tabWidth": 4,
"singleQuote": true,
"trailingComma": "es5",
"jsxBracketSameLine": true,
"endOfLine": "auto",
"arrowParens": "avoid"
}
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@
"@types/commander": "^2.12.2",
"@types/jest": "^26.0.15",
"@types/node": "^12.7.8",
"jest": "^26.6.0"
"husky": "^4.3.8",
"jest": "^26.6.0",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0"
},
"repository": {
"type": "git",
"url": "https://github.com/smikula/good-fences.git"
},
"license": "MIT"
"license": "MIT",
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
}
6 changes: 2 additions & 4 deletions sample/src/componentA/fence.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"tags": [
"tagA"
],
"tags": ["tagA"],
"exports": [
"componentA",
{
Expand All @@ -10,4 +8,4 @@
}
],
"imports": []
}
}
6 changes: 2 additions & 4 deletions sample/src/componentB/fence.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"tags": [
"tagB"
],
"tags": ["tagB"],
"exports": [
{
"modules": "componentB",
"accessibleTo": "tagA"
}
]
}
}
10 changes: 3 additions & 7 deletions sample/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
"noImplicitAny": false,
"noUnusedLocals": true
},
"exclude": [
"lib"
],
"include": [
"src/**/*"
]
}
"exclude": ["lib"],
"include": ["src/**/*"]
}
5 changes: 4 additions & 1 deletion src/core/ImportRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export default class ImportRecord {
// Is this import an external dependency (i.e. is it under node_modules or outside the rootDir)?
get isExternal() {
let isInNodeModules = this.filePath.split(path.sep).indexOf('node_modules') != -1;
let isUnderRootFolder = getOptions().rootDir.some(rootDir => this.filePath.startsWith(rootDir));
let isUnderRootFolder = getOptions().rootDir.some(rootDir =>
this.filePath.startsWith(rootDir)
);

let isLocalRelativePath = this.filePath.startsWith('./');
let isExternalPath = !isUnderRootFolder && !isLocalRelativePath;
return isInNodeModules || isExternalPath;
Expand Down
2 changes: 1 addition & 1 deletion src/types/ConfigSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Config from './config/Config';

export default interface ConfigSet {
[path: string]: Config;
};
}
2 changes: 1 addition & 1 deletion src/types/GoodFencesError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export default interface GoodFencesError {
rawImport?: string;
fencePath: string;
detailedMessage: string;
};
}
2 changes: 1 addition & 1 deletion src/types/GoodFencesResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import GoodFencesError from './GoodFencesError';
export default interface GoodFencesResult {
errors: GoodFencesError[];
warnings: GoodFencesError[];
};
}
2 changes: 1 addition & 1 deletion src/types/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default interface Config {
exports: ExportRule[];
dependencies: DependencyRule[];
imports: string[];
};
}
2 changes: 1 addition & 1 deletion src/types/config/DependencyRule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface DependencyRule {
dependency: string;
accessibleTo: string | string[];
};
}
2 changes: 1 addition & 1 deletion src/types/config/ExportRule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface ExportRule {
modules: string;
accessibleTo: string | string[];
};
}
8 changes: 5 additions & 3 deletions src/utils/getOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export function setOptions(rawOptions: RawOptions) {
const nonNormalizedRoots: string[] = Array.isArray(rawOptions.rootDir)
? rawOptions.rootDir
: [rawOptions.rootDir || process.cwd()];
const rootDir: NormalizedPath[] = nonNormalizedRoots.map(
(individualRootDirPath: string) => normalizePath(individualRootDirPath)

const rootDir: NormalizedPath[] = nonNormalizedRoots.map((individualRootDirPath: string) =>
normalizePath(individualRootDirPath)
);

const project = rawOptions.project
? normalizePath(rawOptions.project)
: normalizePath(rootDir[0], "tsconfig.json");
: normalizePath(rootDir[0], 'tsconfig.json');

options = {
project,
Expand Down
2 changes: 1 addition & 1 deletion test/endToEnd/endToEndTests.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"fencePath": "sample/src/componentA/fence.json"
}
]
}
}
11 changes: 3 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
"noImplicitThis": true,
"skipLibCheck": true
},
"exclude": [
"node_modules",
"lib"
],
"include": [
"src/**/*"
]
}
"exclude": ["node_modules", "lib"],
"include": ["src/**/*"]
}
Loading

0 comments on commit 47f75d2

Please sign in to comment.