-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Possibility to override config (#45)
* fix: Catch the ServiceError so it is possible catch the TypeError (etc). * feat: Implement ConfigProvider to allow user to add config file to switch off some practices via name. * feat: Bind the ConfigProvider. * feat: implement ConfigProvider into Scanner. * feat: Allow user to setup yaml config. * WIP: ConfigProvider * chore: add some architecture hints * WIP: CongiProvider binding * chore: fix config provider * fix: Make the ConfigProvider work. * WIP: try to save the default impact * feat: Report the changed impact in CLI Reporter. * fix: unnecessary async in JSONReport * feat: add off type to PracticeImpact, fix: rename offedPractices to practicesOff * feat: Show deep JSON report. * fix: refactor if else to ternary operator, change showHidden to false * WIP: add config interface * feat: add PracticeImpactType * fix: Use the id of practice for switching off tha preacitces in config * feat: Add info about config file in README.md * Update README.md Co-Authored-By: Prokop Simek <prokopsimek@users.noreply.github.com> * Update src/contexts/projectComponent/projectComponentContextBinding.ts Co-Authored-By: Prokop Simek <prokopsimek@users.noreply.github.com> * Update src/scanner/Scanner.ts Co-Authored-By: Prokop Simek <prokopsimek@users.noreply.github.com> * fix: Show practices switched off in report, fix: Use enum PracticeImpact instead of new type PracticeImpactType, fix: add defaultImpact in decorator. * refactor: Split the detectPractices() -> implement filterPractices() in ScannerUtils * refactor: Add filtering just name from metadata to filterPractices() * refactor: Passing practicesOff * test: Add test for filterPractices() * Update src/index.ts * fix: remove unnecessary code * fix: Change colour of output if no practice was switched off
- Loading branch information
1 parent
6a01000
commit 7d5b33f
Showing
20 changed files
with
346 additions
and
83 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { inject, injectable } from 'inversify'; | ||
import yaml from 'js-yaml'; | ||
import _ from 'lodash'; | ||
import { IFileInspector } from '../inspectors/IFileInspector'; | ||
import { Types } from '../types'; | ||
import { IConfigProvider, Config } from './IConfigProvider'; | ||
|
||
@injectable() | ||
export class ConfigProvider implements IConfigProvider { | ||
private readonly fileInspector: IFileInspector; | ||
config: Config | undefined; | ||
|
||
constructor(@inject(Types.IFileInspector) fileInspector: IFileInspector) { | ||
this.fileInspector = fileInspector; | ||
this.config = undefined; | ||
} | ||
|
||
async init() { | ||
const regexConfigFile = new RegExp('dxscannerrc.', 'i'); | ||
|
||
const configFileMetadata = await this.fileInspector.scanFor(regexConfigFile, '/', { shallow: true }); | ||
|
||
if (configFileMetadata.length === 0) { | ||
return undefined; | ||
} | ||
const configFile = configFileMetadata[0]; | ||
|
||
let parsedContent; | ||
const content = await this.fileInspector.readFile(configFile.path); | ||
|
||
if (configFile.extension === '.json' || configFile.extension === '') { | ||
parsedContent = JSON.parse(content); | ||
} | ||
if (configFile.extension === '.yml' || configFile.extension === '.yaml') { | ||
parsedContent = yaml.safeLoad(content); | ||
} | ||
|
||
this.config = parsedContent; | ||
} | ||
|
||
getOverridenPractice(practiceId: string) { | ||
return _.get(this.config, ['practices', practiceId]); | ||
} | ||
} |
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,43 @@ | ||
import { PracticeImpact } from '../model'; | ||
|
||
export interface IConfigProvider { | ||
init(): Promise<void>; | ||
getOverridenPractice(practiceId: string): PracticeImpact; | ||
} | ||
|
||
export interface Config { | ||
practices?: { | ||
[key in Practices]?: PracticeImpact; | ||
}; | ||
tokens?: { | ||
[key in Service]: string; | ||
}; | ||
} | ||
|
||
enum Service { | ||
Slack = 'Slack', | ||
} | ||
|
||
enum Practices { | ||
'JavaScript.TypeScriptUsedPractice' = 'JavaScript.TypeScriptUsedPractice', | ||
'JavaScript.PrettierUsedPractice' = 'JavaScript.PrettierUsedPractice', | ||
'JavaScript.ESLintUsedPractice' = 'JavaScript.ESLintUsedPractice', | ||
'LanguageIndependent.LockfileIsPresentPractice' = 'LanguageIndependent.LockfileIsPresentPractice', | ||
'JavaScript.JsFrontendTestingFrameworkUsedPractice' = 'JavaScript.JsFrontendTestingFrameworkUsedPractice', | ||
'JavaScript.JsBackendTestingFrameworkUsedPractice' = 'JavaScript.JsBackendTestingFrameworkUsedPractice', | ||
'JavaScript.JsLoggerUsedPractice' = 'JavaScript.JsLoggerUsedPractice', | ||
'LanguageIndependent.LicenseIsPresentPractice' = 'LanguageIndependent.LicenseIsPresentPractice', | ||
'LanguageIndependent.ReadmeIsPresentPractice' = 'LanguageIndependent.ReadmeIsPresentPractice', | ||
'LanguageIndependent.CIUsedPractice' = 'LanguageIndependent.CIUsedPractice', | ||
'JavaScript.JsFEBuildtoolUsedPractice' = 'JavaScript.JsFEBuildtoolUsedPractice', | ||
'JavaScript.JsPackageJsonConfigurationSetCorrectlyPractice' = 'JavaScript.JsPackageJsonConfigurationSetCorrectlyPractice', | ||
'JavaScript.JsPackageManagementUsedPractice' = 'JavaScript.JsPackageManagementUsedPractice', | ||
'JavaScript.DeprecatedTSLintPractice' = 'JavaScript.DeprecatedTSLintPractice', | ||
'LanguageIndependent.DockerizationUsedPractice' = 'LanguageIndependent.DockerizationUsedPractice', | ||
'LanguageIndependent.EditorConfigIsPresentPractice' = 'LanguageIndependent.EditorConfigIsPresentPractice', | ||
'LanguageIndependent.DependenciesVersionPractice' = 'LanguageIndependent.DependenciesVersionPractice', | ||
'JavaScript.JsGitignoreIsPresentPractice' = 'JavaScript.JsGitignoreIsPresentPractice', | ||
'JavaScript.JsGitignoreCorrectlySetPractice' = 'JavaScript.JsGitignoreCorrectlySetPractice', | ||
UnitTestPractice = 'UnitTestPractice', | ||
PullRequestPractice = 'PullRequestPractice', | ||
} |
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
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
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
Oops, something went wrong.