-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from utilitywarehouse/noimplicitany-flag
Make our code base more safe with Typescript more strict
- Loading branch information
Showing
60 changed files
with
1,690 additions
and
1,102 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 @@ | ||
src/generated/* |
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,36 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module", | ||
"project": "./tsconfig.json", | ||
"tsconfigRootDir": "./" | ||
}, | ||
"rules": { | ||
"indent": ["error", 2], | ||
"max-len": ["error", 150], | ||
"linebreak-style": ["error", "unix"], | ||
"quotes": ["error", "single"], | ||
"semi": ["error", "always"], | ||
"object-curly-spacing": ["error", "always"], | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-empty-interface": "off", | ||
"@typescript-eslint/explicit-function-return-type": ["error", { | ||
"allowExpressions": true, | ||
"allowTypedFunctionExpressions": true, | ||
"allowHigherOrderFunctions": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules/ | ||
dist/ | ||
yarn-error.log | ||
yarn-error.log | ||
.idea/ | ||
.vscode/ |
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 |
---|---|---|
@@ -1,2 +1,19 @@ | ||
# nimbus-graphql | ||
A GraphQL Framework with batteries included | ||
|
||
# Developing | ||
|
||
## VSCode users | ||
|
||
Since `tslint` is being deprecated, we are using `eslint` to make this VSCode extension report issues on typescript files we need to add a setting. | ||
To do that, add the following snippet on `settings.json`: | ||
```json | ||
{ | ||
"eslint.validate": [ | ||
"javascript", | ||
"javascriptreact", | ||
"typescript", | ||
"typescriptreact" | ||
] | ||
} | ||
``` |
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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import {StringBoolean} from '../index'; | ||
import { StringBoolean } from '../index'; | ||
|
||
test('coercion', () => { | ||
expect(StringBoolean('true')).toBe(true); | ||
expect(StringBoolean('false')).toBe(false); | ||
expect(StringBoolean('whatever')).toBe(false); | ||
expect(StringBoolean('TRUE')).toBe(true); | ||
expect(StringBoolean('true')).toBe(true); | ||
expect(StringBoolean('false')).toBe(false); | ||
expect(StringBoolean('whatever')).toBe(false); | ||
expect(StringBoolean('TRUE')).toBe(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export default { | ||
test: 'default-value', | ||
other: 'other-value', | ||
nan: Number('az'), | ||
test: 'default-value', | ||
other: 'other-value', | ||
nan: Number('az'), | ||
}; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import {Section} from '../../config.service'; | ||
import { Section } from '../../config.service'; | ||
|
||
export default { | ||
[Section]: 'test', | ||
test: 'section-value', | ||
nan: Number('az'), | ||
[Section]: 'test', | ||
test: 'section-value', | ||
nan: Number('az'), | ||
}; |
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 |
---|---|---|
@@ -1,50 +1,50 @@ | ||
import {Config} from '../config.service'; | ||
import { Config } from '../config.service'; | ||
|
||
describe('config.service', () => { | ||
|
||
let config; | ||
|
||
beforeAll(async () => { | ||
config = await Config.load(__dirname, 'fixtures/*.config.ts'); | ||
}); | ||
|
||
test('getting default value', () => { | ||
expect(config.get('test')).toBe('default-value'); | ||
}); | ||
|
||
test('getting section value', () => { | ||
expect(config.section('test').get('test')).toBe('section-value'); | ||
}); | ||
|
||
test('getting section value with fallback', () => { | ||
expect(config.section('test').get('other')).toBe('other-value'); | ||
}); | ||
|
||
test('exception on unknown section key', () => { | ||
expect(() => { | ||
config.section('test').get('n-a'); | ||
}).toThrow('could not find requested key'); | ||
}); | ||
|
||
test('exception on unknown default key', () => { | ||
expect(() => { | ||
config.get('n-a'); | ||
}).toThrow('could not find requested key'); | ||
}); | ||
|
||
test('exception on NaN section value (bad coercion)', () => { | ||
expect(() => { | ||
config.section('test').get('nan'); | ||
}).toThrow('NaN encountered for key'); | ||
}); | ||
|
||
test('exception on NAN default value (bad coercion)', () => { | ||
expect(() => { | ||
config.get('nan'); | ||
}).toThrow('NaN encountered for key'); | ||
}); | ||
|
||
test('reverting to default on unknown section', () => { | ||
expect(config.section('n-a').get('test')).toBe('default-value'); | ||
}); | ||
}) | ||
let config: Config; | ||
|
||
beforeAll(() => { | ||
config = Config.load(__dirname, 'fixtures/*.config.ts'); | ||
}); | ||
|
||
test('getting default value', () => { | ||
expect(config.get('test')).toBe('default-value'); | ||
}); | ||
|
||
test('getting section value', () => { | ||
expect(config.section('test').get('test')).toBe('section-value'); | ||
}); | ||
|
||
test('getting section value with fallback', () => { | ||
expect(config.section('test').get('other')).toBe('other-value'); | ||
}); | ||
|
||
test('exception on unknown section key', () => { | ||
expect(() => { | ||
config.section('test').get('n-a'); | ||
}).toThrow('could not find requested key'); | ||
}); | ||
|
||
test('exception on unknown default key', () => { | ||
expect(() => { | ||
config.get('n-a'); | ||
}).toThrow('could not find requested key'); | ||
}); | ||
|
||
test('exception on NaN section value (bad coercion)', () => { | ||
expect(() => { | ||
config.section('test').get('nan'); | ||
}).toThrow('NaN encountered for key'); | ||
}); | ||
|
||
test('exception on NAN default value (bad coercion)', () => { | ||
expect(() => { | ||
config.get('nan'); | ||
}).toThrow('NaN encountered for key'); | ||
}); | ||
|
||
test('reverting to default on unknown section', () => { | ||
expect(config.section('n-a').get('test')).toBe('default-value'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import {ConfigProvider} from './config.provider'; | ||
import {ConfigContainer} from './config.container'; | ||
import { ConfigProvider } from './config.provider'; | ||
import { ConfigContainer } from './config.container'; | ||
|
||
export class Getter implements ConfigProvider { | ||
constructor( | ||
private readonly name: string, | ||
private readonly section: ConfigContainer = {}, | ||
private readonly defaults: ConfigContainer = {}) { | ||
} | ||
constructor( | ||
private readonly name: string, | ||
private readonly section: ConfigContainer = {}, | ||
private readonly defaults: ConfigContainer = {}) { | ||
} | ||
|
||
get(key: string): any { | ||
get(key: string): any { | ||
|
||
let value; | ||
let value; | ||
|
||
if (this.section.hasOwnProperty(key)) { | ||
value = this.section[key]; | ||
} | ||
const sectionHasProperty = Object.prototype.hasOwnProperty.call(this.section, key); | ||
const defaultsHasProperty = Object.prototype.hasOwnProperty.call(this.defaults, key); | ||
|
||
if (!this.section.hasOwnProperty(key) && this.defaults.hasOwnProperty(key)) { | ||
value = this.defaults[key]; | ||
} | ||
if (sectionHasProperty) { | ||
value = this.section[key]; | ||
} | ||
|
||
if (Number.isNaN(value)) { | ||
throw new Error(`NaN encountered for key '${key}' for section '${this.name}' in config`); | ||
} else if (value === undefined) { | ||
throw new Error(`could not find requested key '${key}' for section '${this.name}' in config`); | ||
} | ||
if (!sectionHasProperty && defaultsHasProperty) { | ||
value = this.defaults[key]; | ||
} | ||
|
||
return value; | ||
if (Number.isNaN(value)) { | ||
throw new Error(`NaN encountered for key '${key}' for section '${this.name}' in config`); | ||
} else if (value === undefined) { | ||
throw new Error(`could not find requested key '${key}' for section '${this.name}' in config`); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
} |
Oops, something went wrong.