-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christopher Quadflieg
committed
Jul 10, 2020
1 parent
5ec5687
commit 838cfb8
Showing
3 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Configuration } from './types' | ||
|
||
export function isConfiguration(value: unknown): value is Configuration { | ||
// Config must be an object | ||
if (typeof value !== 'object') { | ||
return false | ||
} | ||
|
||
// Config must not be null | ||
if (value === null) { | ||
return false | ||
} | ||
|
||
// This helps to get better support for TypeScript | ||
const config = value as Record<string, unknown> | ||
|
||
// If extends is defined, it must be an array | ||
if (config.extends !== undefined) { | ||
if (!Array.isArray(config.extends)) { | ||
return false | ||
} | ||
|
||
// Any value within extens must be a string | ||
for (const extension of config.extends) { | ||
if (typeof extension !== 'string') { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
// If extends is defined, it must be an object | ||
if (config.rules !== undefined) { | ||
if (typeof config.rules !== 'object' && config.rules !== null) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters