Skip to content

Commit b4da6ec

Browse files
authored
Merge pull request #24 from matsoftware/fix-imports-parsing
Fix on parsing import statements with complex comments
2 parents ee8f67c + 5556e17 commit b4da6ec

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
56
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
67

8+
## UNRELEASED
9+
10+
### Fixed
11+
12+
- [PR-24](https://github.com/matsoftware/swift-code-metrics/pull/24) Fix on parsing import statements with complex comments
13+
714
## [1.4.1](https://github.com/matsoftware/swift-code-metrics/releases/tag/1.4.1) - 2020-07-29
815

916
### Added
1017

11-
- [PR-22](https://github.com/matsoftware/swift-code-metrics/pull/22) Support for iOS 14 / macOS 11 frameworks
18+
- [PR-22](https://github.com/matsoftware/swift-code-metrics/pull/22) Support for iOS 14 / macOS 11 frameworks
1219

1320
## [1.4.0](https://github.com/matsoftware/swift-code-metrics/releases/tag/1.4.0) - 2020-02-25
1421

1522
### Added
1623

17-
- [PR-17](https://github.com/matsoftware/swift-code-metrics/pull/17) Support for iOS 13 / Mac OSX 15 frameworks
24+
- [PR-17](https://github.com/matsoftware/swift-code-metrics/pull/17) Support for iOS 13 / Mac OSX 15 frameworks
1825

1926
### Fixed
2027

@@ -37,7 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3744
### Fixed
3845

3946
- [PR-6](https://github.com/matsoftware/swift-code-metrics/pull/6)
40-
Gracefully fail on empty projects or code without modules
47+
Gracefully fail on empty projects or code without modules
4148

4249
## [1.2.2](https://github.com/matsoftware/swift-code-metrics/releases/tag/1.2.2) - 2019-02-10
4350

@@ -60,6 +67,7 @@ Gracefully fail on empty projects or code without modules
6067
- Added NOI (number of imports) metric and graph
6168

6269
### Changed
70+
6371
- Improved dependency graphs by using a variable node and arrow thickness
6472
- Improved parsing of import statements
6573
- Improved bar charts' reports

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmatsoftware%2Fswift-code-metrics.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmatsoftware%2Fswift-code-metrics?ref=badge_shield) [![License](https://img.shields.io/badge/license-MIT-blue.svg?x=1)](LICENSE) [![Build Status](https://travis-ci.org/matsoftware/swift-code-metrics.svg?branch=master)](https://travis-ci.org/matsoftware/swift-code-metrics) [![codecov](https://codecov.io/gh/matsoftware/swift-code-metrics/branch/master/graph/badge.svg)](https://codecov.io/gh/matsoftware/swift-code-metrics) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2ff12e0cafce4ec68024d47b000d2e42)](https://app.codacy.com/app/matsoftware/swift-code-metrics?utm_source=github.com&utm_medium=referral&utm_content=matsoftware/swift-code-metrics&utm_campaign=Badge_Grade_Dashboard)
1+
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmatsoftware%2Fswift-code-metrics.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmatsoftware%2Fswift-code-metrics?ref=badge_shield) [![License](https://img.shields.io/badge/license-MIT-blue.svg?x=1)](LICENSE) [![Build Status](https://travis-ci.org/matsoftware/swift-code-metrics.svg?branch=master)](https://travis-ci.org/matsoftware/swift-code-metrics) [![codecov](https://codecov.io/gh/matsoftware/swift-code-metrics/branch/master/graph/badge.svg)](https://codecov.io/gh/matsoftware/swift-code-metrics) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2ff12e0cafce4ec68024d47b000d2e42)](https://app.codacy.com/app/matsoftware/swift-code-metrics?utm_source=github.com&utm_medium=referral&utm_content=matsoftware/swift-code-metrics&utm_campaign=Badge_Grade_Dashboard)
22
[![PyPI](https://img.shields.io/pypi/v/swift-code-metrics.svg)](https://pypi.python.org/pypi/swift-code-metrics)
33

44
# swift-code-metrics
55

66
Code metrics analyzer for Swift projects.
77

88
| ![Example code distribution](https://raw.githubusercontent.com/matsoftware/swift-code-metrics/master/docs/assets/code_distribution.jpeg) ![Example deviation main sequence](https://raw.githubusercontent.com/matsoftware/swift-code-metrics/master/docs/assets/example_deviation_main_sequence.jpeg) |
9-
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
9+
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1010
| ![Example internal distribution](https://raw.githubusercontent.com/matsoftware/swift-code-metrics/master/docs/assets/example_internal_deps_graph.jpeg) |
1111

1212
## Introduction
1313

1414
The goal of this software is to provide an insight of the architectural state of a software written in `Swift` that consists in several modules.
1515
Inspired by the book of Robert C. Martin, _Clean Architecture_, the software will scan the project to identify the different components in order to assess several common code metrics in the software industry:
16+
1617
- the overall number of concrete classes and interfaces
1718
- the _instability_ and _abstractness_ of the framework
1819
- the _distance from the main sequence_
@@ -52,8 +53,8 @@ Please follow the [guide](https://github.com/matsoftware/swift-code-metrics/tree
5253
## Current limitations
5354

5455
- This tool is designed for medium/large codebases composed by different frameworks.
55-
The script will scan the directory and it will identify the frameworks by the name of the 'root' folder,
56-
so it's strictly dependent on the file hierarchy (unless a [project path override file](docs/GUIDE.md#Project-paths-override) is specified)
56+
The script will scan the directory and it will identify the frameworks by the name of the 'root' folder,
57+
so it's strictly dependent on the file hierarchy (unless a [project path override file](docs/GUIDE.md#Project-paths-override) is specified)
5758

5859
- Libraries built with `spm` are not supported.
5960

swift_code_metrics/_helpers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,16 @@ class ParsingHelpers:
220220

221221
# Constants - Regex patterns
222222

223-
BEGIN_COMMENT = '^//*'
224-
END_COMMENT = '\*/$'
225-
SINGLE_COMMENT = '^//'
223+
BEGIN_COMMENT = r'^//*'
224+
END_COMMENT = r'\*/$'
225+
SINGLE_COMMENT = r'^//'
226226

227-
IMPORTS = '(?:(?<=^import )|@testable import )(?:\\b\w+\s|)([^.; ]+)'
227+
IMPORTS = r'(?:(?<=^import )|@testable import )(?:\b\w+\s|)([^.; \/]+)'
228228

229-
PROTOCOLS = '.*protocol (.*?)[:|{|\s]'
230-
STRUCTS = '.*struct (.*?)[:|{|\s]'
231-
CLASSES = '.*class (.*?)[:|{|\s]'
232-
FUNCS = '.*func (.*?)[:|\(|\s]'
229+
PROTOCOLS = r'.*protocol (.*?)[:|{|\s]'
230+
STRUCTS = r'.*struct (.*?)[:|{|\s]'
231+
CLASSES = r'.*class (.*?)[:|{|\s]'
232+
FUNCS = r'.*func (.*?)[:|\(|\s]'
233233

234234
# Static helpers
235235

swift_code_metrics/tests/test_helper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def test_helpers_imports_subcomponent_expectTrue(self):
6363
string = 'import struct Foundation.KeyChain'
6464
self.assertEqual('Foundation', _helpers.ParsingHelpers.extract_substring_with_pattern(regex, string))
6565

66+
def test_helpers_imports_comments_expectTrue(self):
67+
regex = _helpers.ParsingHelpers.IMPORTS
68+
string = 'import Contacts // fix for `dyld: Library not loaded: @rpath/libswiftContacts.dylib`'
69+
self.assertEqual('Contacts', _helpers.ParsingHelpers.extract_substring_with_pattern(regex, string))
70+
6671
def test_helpers_imports_specialwords_expectFalse(self):
6772
regex = _helpers.ParsingHelpers.IMPORTS
6873
string = 'importedMigratedComponents: AnyImportedComponent'

0 commit comments

Comments
 (0)