Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.1.2
- Improve CodeClimate report

## 1.1.1
- Added support extension methods

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

### Simple usage:
```bash
pub global activate metrics
pub global activate dart_code_metrics
metrics lib
```
5 changes: 4 additions & 1 deletion bin/metrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ void main(List<String> args) {
arguments[helpFlagName] as bool ||
arguments.rest.length != 1) {
showUsage = true;
} else if (!File(arguments.rest.single).existsSync()) {
print("Can't find directory ${arguments.rest.single}");
showUsage = true;
}

if (showUsage) {
Expand All @@ -62,7 +65,7 @@ void main(List<String> args) {
}

final rootFolder = arguments[rootFolderName] as String;
var dartFilePaths = Glob('${arguments.rest.first}**.dart')
var dartFilePaths = Glob('${arguments.rest.single}**.dart')
.listSync(root: rootFolder, followLinks: false)
.whereType<File>()
.map((entity) => entity.path);
Expand Down
49 changes: 22 additions & 27 deletions lib/src/reporters/code_climate/code_climate_issue.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:meta/meta.dart';

@immutable
class CodeClimateLineColumnPosition {
final int line;
class CodeClimateLocationLines {
final int begin;
final int end;

const CodeClimateLineColumnPosition(this.line);
const CodeClimateLocationLines(this.begin, this.end);

Map<String, int> toJson() => {
'line': line,
'column': 1,
};
}

@immutable
class CodeClimatePosition {
final CodeClimateLineColumnPosition begin;
final CodeClimateLineColumnPosition end;

const CodeClimatePosition(this.begin, this.end);

Map<String, Object> toJson() => {
'begin': begin.toJson(),
'end': end.toJson(),
'begin': begin,
'end': end,
};
}

@immutable
class CodeClimateLocation {
final String path;
final CodeClimatePosition positions;
final CodeClimateLocationLines positions;

const CodeClimateLocation(this.path, this.positions);

Expand All @@ -47,16 +38,19 @@ class CodeClimateIssue {
final String checkName;
final String description;
final CodeClimateLocation location;
final String fingerprint;

const CodeClimateIssue._(this.checkName, this.description, this.location);
const CodeClimateIssue._(
this.checkName, this.description, this.location, this.fingerprint);

factory CodeClimateIssue._create(
String name, String desc, int startLine, int endLine, String fileName) {
final position = CodeClimatePosition(
CodeClimateLineColumnPosition(startLine),
CodeClimateLineColumnPosition(endLine));
final location = CodeClimateLocation(fileName, position);
return CodeClimateIssue._(name, desc, location);
final locationLines = CodeClimateLocationLines(startLine, endLine);
final location = CodeClimateLocation(fileName, locationLines);
final fingerprint = md5
.convert(utf8.encode('$name $desc $startLine $endLine $fileName'))
.toString();
return CodeClimateIssue._(name, desc, location, fingerprint);
}

factory CodeClimateIssue.linesOfCode(int startLine, int endLine,
Expand Down Expand Up @@ -86,9 +80,10 @@ class CodeClimateIssue {
Map<String, Object> toJson() => {
'type': type,
'check_name': checkName,
'categories': categories,
'remediation_points': remediationPoints,
'description': description,
'categories': categories,
'location': location.toJson(),
'remediation_points': remediationPoints,
'fingerprint': fingerprint,
};
}
9 changes: 2 additions & 7 deletions lib/src/reporters/code_climate/code_climate_reporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import 'package:dart_code_metrics/src/reporters/utility_selector.dart';
import 'package:meta/meta.dart';

class CodeClimateReporter implements Reporter {
static const _nullCharacter = '\u0000';

final Config reportConfig;
CodeClimateReporter({@required this.reportConfig});

Expand All @@ -20,10 +18,7 @@ class CodeClimateReporter implements Reporter {
return;
}

final data = records.map(_toIssues).expand((r) => r);
for (final issue in data) {
print(json.encode(issue) + _nullCharacter);
}
print(json.encode(records.map(_toIssues).expand((r) => r).toList()));
}

bool _isIssueLevel(ViolationLevel level) =>
Expand All @@ -48,7 +43,7 @@ class CodeClimateReporter implements Reporter {
report.cyclomaticComplexity,
record.relativePath,
key,
reportConfig.linesOfCodeWarningLevel));
reportConfig.cyclomaticComplexityWarningLevel));
}

if (_isIssueLevel(report.maintainabilityIndexViolationLevel)) {
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_code_metrics
description: Command line tool which helps to improve code quality
version: 1.1.1
version: 1.1.2
homepage: https://github.com/wrike/dart-code-metrics
author: Dmitry Krutskih <dmitry.krutskikh@team.wrike.com>

Expand All @@ -12,6 +12,7 @@ dependencies:
ansicolor: ^1.0.0
args: ^1.5.0
built_collection: ^4.2.0
crypto: ^2.1.0
glob: ^1.2.0
html: '>=0.13.0 < 1.0.0'
meta: ^1.1.0
Expand Down