Skip to content

Commit

Permalink
refactor(types): make the type definition tslint recommended compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Jan 21, 2018
1 parent bc8440b commit 6dc254e
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Expand Up @@ -9,6 +9,7 @@ test_async_node_latest:
script:
- npm install
- npm run lint
- npm run lint:types
- npm run depcruise
- npm run nsp
- npm run test:cover
Expand Down
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -67,6 +67,7 @@ dev-build: bin/dependency-cruise $(GENERATED_SOURCES) $(ALL_SRC) .npmignore

lint:
$(NPM) run lint
$(NPM) run lint:types

lint-fix:
$(NPM) run lint:fix
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Expand Up @@ -19,6 +19,8 @@ test_script:
- npm --version
# run tests
- npm run depcruise
- npm run lint
- npm run lint:types
- npm run test:long

# Don't actually build.
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -12,6 +12,7 @@
"depcruise": "node ./bin/dependency-cruise --validate .dependency-cruiser-custom.json src bin/dependency-cruise test",
"depcruise:graph": "node ./bin/dependency-cruise --exclude \"(^node_modules|^fs$|^path$)\" --output-type dot --validate .dependency-cruiser-custom.json bin/dependency-cruise | dot -T svg > tmp_deps.svg",
"lint": "eslint bin/dependency-cruise src test",
"lint:types": "tslint types/dependency-cruiser.d.ts",
"lint:fix": "eslint --fix bin/dependency-cruise src test",
"nsp": "nsp check",
"npm-check-updates": "ncu --upgrade",
Expand Down Expand Up @@ -53,6 +54,7 @@
"mocha": "5.0.0",
"npm-check-updates": "2.14.0",
"nsp": "3.1.0",
"tslint": "5.9.1",
"typescript": "2.6.2"
},
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions tslint.json
@@ -0,0 +1,9 @@
{
"defaultSeverity": "warn",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}
100 changes: 61 additions & 39 deletions types/dependency-cruiser.d.ts
@@ -1,8 +1,8 @@
/**
* all supported extensions; for each extension whether or not
* all supported extensions; for each extension whether or not
* it is supported in the current environment
*/
export const allExtensions: {
export const allExtensions: Array<{
/**
* File extension (e.g. ".js", ".ts", ".jsx")
*/
Expand All @@ -11,9 +11,9 @@ export const allExtensions: {
* Whether or not the extension is available as supported in the current environment
*/
available: boolean;
}[];
}>;

export type AvailableTranspilersType = {
export type AvailableTranspilersType = Array<{
/**
* The name of the transpiler (e.g. "typescript", "coffeescript")
*/
Expand All @@ -26,17 +26,19 @@ export type AvailableTranspilersType = {
* Whether or not the transpiler is available in the current environment
*/
available: boolean;
}[];
}>;

export type ModuleSystemType = "cjs" | "amd" | "es6";

export type OutputType = "json" | "html" | "dot" | "csv" | "err";

export type SeverityType = "error" | "warn" | "info";

export type DependencyType = "local" | "npm" | "npm-dev" | "npm-optional" | "npm-peer" | "npm-bundled" | "npm-no-pkg" | "npm-unknown" | "core" | "unknown" | "undetermined" | "deprecated";
export type DependencyType = "local" | "npm" | "npm-dev" | "npm-optional"
| "npm-peer" | "npm-bundled" | "npm-no-pkg" | "npm-unknown"
| "core" | "unknown" | "undetermined" | "deprecated";

export type RestrictionType = {
export interface IRestriction {
/**
* A regular expression an end of a dependency should match to be catched by this rule.
*/
Expand All @@ -47,7 +49,7 @@ export type RestrictionType = {
pathNot?: string;
}

export type ToRestrictionType = {
export interface IToRestriction {
/**
* A regular expression an end of a dependency should match to be catched by this rule.
*/
Expand All @@ -57,7 +59,8 @@ export type ToRestrictionType = {
*/
pathNot?: string;
/**
* Whether or not to match modules dependency-cruiser could not resolve (and probably aren't on disk). For this one too: leave out if you don't care either way.
* Whether or not to match modules dependency-cruiser could not resolve (and probably
* aren't on disk). For this one too: leave out if you don't care either way.
*/
couldNotResolve?: boolean;
/**
Expand All @@ -69,84 +72,102 @@ export type ToRestrictionType = {
*/
dependencyTypes?: DependencyType[];
/**
* If true matches dependencies with more than one dependency type (e.g. defined in _both_ npm and npm-dev)
* If true matches dependencies with more than one dependency type (e.g. defined in
* _both_ npm and npm-dev)
*/
moreThanOneDependencyType?: boolean;
/**
* Whether or not to match modules that were released under one of the mentioned licenses. E.g. to flag GPL-1.0, GPL-2.0 licensed modules (e.g. because your app is not compatible with the GPL) use "GPL"
* Whether or not to match modules that were released under one of the mentioned
* licenses. E.g. to flag GPL-1.0, GPL-2.0 licensed modules (e.g. because your app
* is not compatible with the GPL) use "GPL"
*/
license?: string;
/**
* Whether or not to match modules that were NOT released under one of the mentioned licenses. E.g. to flag everyting non MIT use "MIT" here
* Whether or not to match modules that were NOT released under one of the mentioned
* licenses. E.g. to flag everyting non MIT use "MIT" here
*/
licenseNot?: string;
}

export type RuleType = {
export interface IRule {
/**
* You can use this field to document why the rule is there.
*/
comment?: string;
/**
* Criteria the 'from' end of a dependency should match to be caught by this rule. Leave it empty if you want any module to be matched.
* Criteria the 'from' end of a dependency should match to be caught by this rule.
* Leave it empty if you want any module to be matched.
*/
from: RestrictionType;
from: IRestriction;
/**
* Criteria the 'to' end of a dependency should match to be caught by this rule. Leave it empty if you want any module to be matched.
* Criteria the 'to' end of a dependency should match to be caught by this rule.
* Leave it empty if you want any module to be matched.
*/
to: ToRestrictionType;
to: IToRestriction;
}

export type ForbiddenRuleType = {
export interface IForbiddenRuleType {
/**
* A short name for the rule - will appear in reporters to enable customers to quickly identify a violated rule. Try to keep them short, eslint style. E.g. 'not-to-core' for a rule forbidding dependencies on core modules, or 'not-to-unresolvable' for one that prevents dependencies on modules that probably don't exist.
* A short name for the rule - will appear in reporters to enable customers to
* quickly identify a violated rule. Try to keep them short, eslint style.
* E.g. 'not-to-core' for a rule forbidding dependencies on core modules, or
* 'not-to-unresolvable' for one that prevents dependencies on modules that
* probably don't exist.
*/
name?: string;
/**
* How severe a violation of the rule is. The 'error' severity will make some reporters return a non-zero exit code, so if you want e.g. a build to stop when there's a rule violated: use that.
* How severe a violation of the rule is. The 'error' severity will make some
* reporters return a non-zero exit code, so if you want e.g. a build to stop
* when there's a rule violated: use that.
*/
severity?: SeverityType;
/**
* You can use this field to document why the rule is there.
*/
comment?: string;
/**
* Criteria the 'from' end of a dependency should match to be caught by this rule. Leave it empty if you want any module to be matched.
* Criteria the 'from' end of a dependency should match to be caught by this
* rule. Leave it empty if you want any module to be matched.
*/
from: RestrictionType;
from: IRestriction;
/**
* Criteria the 'to' end of a dependency should match to be caught by this rule. Leave it empty if you want any module to be matched.
* Criteria the 'to' end of a dependency should match to be caught by this
* rule. Leave it empty if you want any module to be matched.
*/
to: ToRestrictionType;
to: IToRestriction;
}


export type RuleSetType = {
export interface IRuleSetType {
/**
* A list of rules that describe dependencies that are not allowed. dependency-cruiser will emit a separate error (warning/ informational) messages for each violated rule.
* A list of rules that describe dependencies that are not allowed.
* dependency-cruiser will emit a separate error (warning/ informational)
* messages for each violated rule.
*/
forbidden?: ForbiddenRuleType[];
forbidden?: IForbiddenRuleType[];
/**
* A list of rules that describe dependencies that are allowed. dependency-cruiser will emit the warning message 'not-in-allowed' for each dependency that does not at least one of them.
* A list of rules that describe dependencies that are allowed.
* dependency-cruiser will emit the warning message 'not-in-allowed' for
* each dependency that does not at least one of them.
*/
allowed?: RuleType[];
allowed?: IRule[];
/**
* Runtime configuration options
*/
options?: CruiseOptionsType;
options?: ICruiseOptions;
}

export type CruiseOptionsType = {
export interface ICruiseOptions {
/**
* if true, will attempt to validate with the rules in ruleSet.
* Default false.
* Default false.
*/
validate?: boolean;
/**
* An object containing the rules to validate against. The rules
* should adhere to the [ruleset schema](https://github.com/sverweij/dependency-cruiser/blob/develop/src/main/ruleSet/jsonschema.json)
* should adhere to the
* [ruleset schema](https://github.com/sverweij/dependency-cruiser/blob/develop/src/main/ruleSet/jsonschema.json)
*/
ruleSet?: RuleSetType;
ruleSet?: IRuleSetType;
/**
* regular expression describing which dependencies the function
* should cruise, but not resolve or follow any further
Expand Down Expand Up @@ -181,13 +202,15 @@ export type CruiseOptionsType = {
}

/**
* Cruises the specified files and files with supported extensions in the specified directories in the pFileDirArray and returns the result in an object.
*
* Cruises the specified files and files with supported extensions in
* the specified directories in the pFileDirArray and returns the result
* in an object.
*
* @param pFileDirArray An array of (names of) files and directories to start the cruise with
* @param pOptions Options that influence the way the dependencies are cruised - and how they are returned.
* @returns pornographic material NSFW
*/
export function cruise(pFileDirArray: Array<string>, pOptions?: CruiseOptionsType ): object;
export function cruise(pFileDirArray: string[], pOptions?: ICruiseOptions ): object;

/**
* Returns an array of supported transpilers and for each of the transpilers
Expand All @@ -201,4 +224,3 @@ export function getAvailableTranspilers(): AvailableTranspilersType;
// const prototype: {
// };
// }

0 comments on commit 6dc254e

Please sign in to comment.