Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/DXHeroes/dx-scanner into …
Browse files Browse the repository at this point in the history
…feature/run-eslint-practice

# Conflicts:
#	src/inspectors/package/PackageInspectorBase.ts
#	src/reporters/CLIReporter.ts
  • Loading branch information
adelkahomolova committed Sep 24, 2019
2 parents c29708a + 721d780 commit f44e100
Show file tree
Hide file tree
Showing 21 changed files with 195 additions and 181 deletions.
18 changes: 0 additions & 18 deletions .gitlab-ci.yml

This file was deleted.

4 changes: 2 additions & 2 deletions renovate.json → .renovaterc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": [
"config:base"
"config:base",
":preserveSemverRanges"
],
"rangeStrategy": "replace",
"automerge": true,
"major": {
"automerge": false
Expand Down
59 changes: 35 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,66 @@
# Contributing to DX Scanner

It seems you want to participate on DX Scanner - that's great! We welcome contributions to our [open source project on GitHub](http://github.com/DXHeroes/dx-scanner).
It seems like you want to participate on our DX Scanner - that's great! We welcome contributions to our [open source project on GitHub](http://github.com/DXHeroes/dx-scanner).

## Introduction
We're glad you're interested in DX Scanner in the way of contributing. We value the pro-community developers as you are.

We are glad that you are interested in DX Scanner in the way of contributing. We value the pro-community developers as you are.

## Help the community
1) Repport an Error or Bug 🐛

1) Report an Error or a Bug 🐛
2) Request a Feature 🆕
3) Contribute Code 👨‍💻👩‍💻
4) Contribute Documentation 📝
3) Contribute to the Code 👨‍💻👩‍💻
4) Contribute to the Documentation 📝
5) Provide Support on Issues ℹ️

## Need a help?
## Need help?

If you have any question about this project, how to use it, or just need clarification about anything open an Issue at https://github.com/DXHeroes/dx-scanner/issues .
If you have any question about this project (for example, how to use it) or if you just need some clarification about anything, please open an Issue at [Issues](https://github.com/DXHeroes/dx-scanner/issues).

## Contributing

1. **Fork & Clone** the repository
2. **Setup** the DX Scanner
- Install Yarn with `npm i -g yarn` if not yet installed
- Install packages with `yarn install`
- Run with `yarn start`
- Build with `yarn build`
- Run tests with `yarn test`
- Lint code with `yarn lint` or `yarn lint:fix` with autofixer
3. **Commit** changes to your own branch
4. **Push** your work back up to your fork
5. Submit a **Pull Request** so that we can review your changes
Follow these steps:

1. **Fork & Clone** the repository
2. **Setup** the DX Scanner
- Install Yarn with `npm i -g yarn` if not yet installed
- Install packages with `yarn install`
- Run with `yarn start`
- Build with `yarn build`
- Run tests with `yarn test`
- Lint code with `yarn lint` or `yarn lint:fix` with autofixer
3. **Commit** changes to your own branch
4. **Push** your work back up to your fork
5. Submit a **Pull Request** so that we can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request.
**NOTE: Be sure to merge the latest from "upstream" before making a pull request.**

## Contribute Code

### Practices
Practices check your repository for using tooling, which improves product development.

Check your repository for using the correct tooling which improves product development.

#### JavaScript/TypeScript
We have more than 10 JS/TS practices for now! If you want to add more, you're more than welcome. Check [JavaScript Practices](https://github.com/DXHeroes/dx-scanner/tree/master/src/practices/JavaScript) to see, what's the pattern of implementation of your own practice.

We have more than 10 JS/TS practices for now! If you want to add more, you are more than welcome. Check [JavaScript Practices](https://github.com/DXHeroes/dx-scanner/tree/master/src/practices/JavaScript) to see what is the pattern of implementation of your own practice.

#### Other Languages
Other languages are not supported yet. If you want to contribute, check [Practices](https://github.com/DXHeroes/dx-scanner/tree/master/src/practices). Get inspired by [Javascript Practices](https://github.com/DXHeroes/dx-scanner/tree/master/src/practices/JavaScript) implementation.

Other languages are not supported yet. If you want to contribute, see [Practices](https://github.com/DXHeroes/dx-scanner/tree/master/src/practices). Get inspired by [Javascript Practices](https://github.com/DXHeroes/dx-scanner/tree/master/src/practices/JavaScript) implementation.

### Inspectors
Inspectors indirectly works with Git code hosting providers APIs. They use common interfaces provided by services so you don't have to which API to use.

Inspectors indirectly work with Git code hosting providers APIs. They use common interfaces provided by services so you do not have to know which API to use.

### Services

There is a [File System Service](https://github.com/DXHeroes/dx-scanner/tree/master/src/services) working with files.

#### Git
Services directly use Git code hosting providers APIs while checking the rate limits. They convert API responses to the own interface, so Inspectors can use them. Only the GitHub Service is implemented for now. If you need e.g. GitLab Service, you can contribute! Get inspired by [GitHub Service](https://github.com/DXHeroes/dx-scanner/blob/master/src/services/git/GitHubService.ts)

Services directly use Git code hosting providers APIs while checking the rate limits. They convert API responses to their own interface so Inspectors can use them. Only the GitHub Service is implemented so far. If you need for example, GitLab Service, you can contribute! Get inspired by [GitHub Service](https://github.com/DXHeroes/dx-scanner/blob/master/src/services/git/GitHubService.ts)

## Copyright and Licensing

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[![Version](https://img.shields.io/npm/v/dx-scanner.svg)](https://npmjs.org/package/dx-scanner)
[![Travis (.org)](https://img.shields.io/travis/DXHeroes/dx-scanner)](https://travis-ci.org/DXHeroes/dx-scanner)
![Codecov](https://img.shields.io/codecov/c/github/DXHeroes/dx-scanner)
![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/DXHeroes/dx-scanner)
![last commit](https://img.shields.io/github/last-commit/DXHeroes/dx-scanner)
![GitHub commit activity](https://img.shields.io/github/commit-activity/w/DXHeroes/dx-scanner)
[![Downloads/week](https://img.shields.io/npm/dw/dx-scanner.svg)](https://npmjs.org/package/dx-scanner)
Expand All @@ -14,9 +13,10 @@

# DX Scanner

DX Scanner is an open-source library that allows you to “measure” Developer Experience directly based on your source code and recommend practices to adopt that will help you to improve your product development.
DX Scanner is an open source library that allows you to “measure” Developer Experience directly based on your source code. DX Scanner recommends practices that can help you with improving your product development.

## What language is supported?

### Which languages are supported?
Language | Supported
------------ | -------------
JavaScript/TypeScript | ✅
Expand Down Expand Up @@ -64,10 +64,10 @@ dxs [path]
```

## Configuration ⚙️
Add ```dxscannerrc.*``` config file to change default configuration. It can be a ```.json```, ```.yml``` even dotfile!
Add ```dxscannerrc.*``` config file to change default configuration. It can be a ```.json```, ```.yml```, and even a dotfile!

**Practices**
You can switch off practices you don't want to scan or change its impact. Use the id of the practice.
You can switch off practices you do not want to scan or change its impact. Use the id of the practice.

Possible impact:
```
Expand All @@ -93,15 +93,15 @@ Example :
```

## Contributing 👩‍💻 👨‍💻
Feel free to contribute to the DX Scanner. If you want to contribute, please follow our [Contribution Guide](CONTRIBUTING.md).
Feel free to contribute to our DX Scanner. Please follow the [Contribution Guide](CONTRIBUTING.md).

## License 📝

The DX Scanner open source project is licensed under the [Attribution-NonCommercial-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-nc-sa/4.0/).

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Many thanks to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
Expand All @@ -120,4 +120,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Any kind of contributions are welcome!
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"@types/glob": "^7.1.1",
"@types/jest": "^24.0.18",
"@types/lodash": "^4.14.137",
"@types/nock": "^10.0.3",
"@types/node": "^12",
"@types/rimraf": "^2.0.2",
"@types/semver": "^6.0.1",
Expand All @@ -70,7 +69,7 @@
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-prettier": "^3.1.0",
"jest": "^24.9.0",
"nock": "^10.0.6",
"nock": "^11.0.0",
"prettier": "^1.18.2",
"rimraf": "^3.0.0",
"semantic-release": "^15.13.21",
Expand Down
4 changes: 2 additions & 2 deletions src/detectors/JavaScript/JavaScriptComponentDetector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('JavaScriptComponentDetector', () => {
mockJsPackageInspector.packages = [mockPackage('webpack')];

mockJsPackageInspector.hasOneOfPackages = (packages: string[]) => {
const files = packages.filter((file) => file === 'express');
const files = packages.filter((file) => file === 'webpack');
if (files.length > 0) {
return true;
}
Expand All @@ -64,6 +64,6 @@ describe('JavaScriptComponentDetector', () => {
detector = new JavaScriptComponentDetector(mockJsPackageInspector);

const components = await detector.detectComponent({ language: ProgrammingLanguage.JavaScript, path: './src' });
expect(components.length).toEqual(0);
expect(components[0].platform).toEqual(ProjectComponentPlatform.UNKNOWN);
});
});
34 changes: 13 additions & 21 deletions src/detectors/JavaScript/JavaScriptComponentDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,24 @@ export class JavaScriptComponentDetector implements IProjectComponentDetector {

const frontendPackages = ['webpack', 'jquery', 'gulp', 'grunt', 'browserify', 'babel'];

let frontendOrBackend;
if (this.packageInspector.hasOneOfPackages(backendPackages)) {
return [
{
framework: ProjectComponentFramework.UNKNOWN,
language: langAtPath.language,
path: langAtPath.path,
platform: ProjectComponentPlatform.BackEnd,
repositoryPath: undefined,
type: ProjectComponentType.Application,
},
];
frontendOrBackend = ProjectComponentPlatform.BackEnd;
}

if (this.packageInspector.hasOneOfPackages(frontendPackages)) {
return [
{
framework: ProjectComponentFramework.UNKNOWN,
language: langAtPath.language,
path: langAtPath.path,
platform: ProjectComponentPlatform.FrontEnd,
repositoryPath: undefined,
type: ProjectComponentType.Application,
},
];
frontendOrBackend = ProjectComponentPlatform.FrontEnd;
}

return [];
return [
{
framework: ProjectComponentFramework.UNKNOWN,
language: langAtPath.language,
path: langAtPath.path,
platform: frontendOrBackend ? frontendOrBackend : ProjectComponentPlatform.UNKNOWN,
repositoryPath: undefined,
type: ProjectComponentType.Application,
},
];
}
}
2 changes: 1 addition & 1 deletion src/inspectors/IPackageInspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface IPackageInspector {
init(): Promise<void>;
hasPackageManagement(): boolean;
findPackages(searchTerm: string | RegExp): Package[];
hasPackage(name: string, options?: PackageOptions): boolean;
hasPackage(name: string | RegExp, options?: PackageOptions): boolean;
findPackage(name: string, options?: PackageOptions): Package | undefined;
hasOneOfPackages(packages: string[]): boolean;
hasLockfile(): boolean | undefined;
Expand Down
13 changes: 9 additions & 4 deletions src/inspectors/package/PackageInspectorBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ export abstract class PackageInspectorBase implements IPackageInspector, IInitia
throw new Error('Method not implemented.');
}

hasPackage(name: string, options?: PackageOptions | undefined): boolean {
hasPackage(name: string | RegExp, options?: PackageOptions | undefined): boolean {
if (!this.packages) {
return false;
}
for (const pkg of this.packages) {
const nameRegExp = new RegExp(name);
if (nameRegExp.test(pkg.name.toLowerCase())) {
return true;
if (typeof name === 'string') {
if (pkg.name.toLowerCase() === name.toLowerCase()) {
return true;
}
} else {
if (name.test(pkg.name.toLowerCase())) {
return true;
}
}
}
return false;
Expand Down
1 change: 1 addition & 0 deletions src/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const createRootContainer = (args: ArgumentsProvider): Container => {
bindScanningStrategyDetectors(container);
bindScanningContext(container);
args.json ? container.bind<IReporter>(Types.IReporter).to(JSONReporter) : container.bind<IReporter>(Types.IReporter).to(CLIReporter);
container.bind(Types.JSONReporter).to(JSONReporter);
container.bind(Types.ArgumentsProvider).toConstantValue(args);
container.bind(Scanner).toSelf();
container.bind(FileSystemService).toSelf();
Expand Down
5 changes: 5 additions & 0 deletions src/lib/assertNever.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ErrorFactory } from "./errors";

export const assertNever = (x: never): never => {
throw ErrorFactory.newInternalError("Unexpected object: " + x);
}
3 changes: 2 additions & 1 deletion src/practices/JavaScript/ESLintUsedPractice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class ESLintUsedPractice implements IPractice {

async evaluate(ctx: PracticeContext): Promise<PracticeEvaluationResult> {
if (ctx.packageInspector) {
if (ctx.packageInspector.hasPackage('eslint')) {
const eslintRegex = new RegExp('eslint');
if (ctx.packageInspector.hasPackage(eslintRegex)) {
return PracticeEvaluationResult.practicing;
} else {
return PracticeEvaluationResult.notPracticing;
Expand Down
Loading

0 comments on commit f44e100

Please sign in to comment.