Skip to content

Commit

Permalink
Refactor license score computation #1180
Browse files Browse the repository at this point in the history
 * make the main loop simpler with configured scoring elements
 * add tests to license score computation
 * add support for future additional scoring elements

Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Nov 8, 2018
1 parent 0eaf1aa commit 3e6b628
Show file tree
Hide file tree
Showing 54 changed files with 4,159 additions and 100 deletions.
297 changes: 197 additions & 100 deletions src/summarycode/score.py

Large diffs are not rendered by default.

261 changes: 261 additions & 0 deletions tests/summarycode/data/score/basic-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
{
"scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"scancode_options": {
"input": "<path>",
"--classify": true,
"--copyright": true,
"--info": true,
"--json": "<file>",
"--license": true,
"--license-clarity-score": true
},
"files_count": 3,
"license_clarity_score": {
"score": 100,
"has_declared_license_in_key_files": true,
"file_level_license_and_copyright_coverage": 1.0,
"has_consistent_key_and_file_level_licenses": true,
"is_using_only_spdx_licenses": true,
"has_full_text_for_all_licenses": true
},
"files": [
{
"path": "basic",
"type": "directory",
"name": "basic",
"base_name": "basic",
"extension": "",
"size": 0,
"date": null,
"sha1": null,
"md5": null,
"mime_type": null,
"file_type": null,
"programming_language": null,
"is_binary": false,
"is_text": false,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"licenses": [],
"license_expressions": [],
"holders": [],
"copyrights": [],
"authors": [],
"is_legal": false,
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 3,
"dirs_count": 0,
"size_count": 4258,
"scan_errors": []
},
{
"path": "basic/README.md",
"type": "file",
"name": "README.md",
"base_name": "README",
"extension": ".md",
"size": 1320,
"date": "2018-10-29",
"sha1": "00f197776bbbca2726c6f1ccf258b6f08e6d3455",
"md5": "c284e8c75f00df967ea1c26065937335",
"mime_type": "text/plain",
"file_type": "ASCII text",
"programming_language": null,
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"licenses": [
{
"key": "mit",
"score": 100.0,
"name": "MIT License",
"short_name": "MIT License",
"category": "Permissive",
"is_exception": false,
"owner": "MIT",
"homepage_url": "http://opensource.org/licenses/mit-license.php",
"text_url": "http://opensource.org/licenses/mit-license.php",
"reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:mit",
"spdx_license_key": "MIT",
"spdx_url": "https://spdx.org/licenses/MIT",
"start_line": 19,
"end_line": 36,
"matched_rule": {
"identifier": "mit.LICENSE",
"license_expression": "mit",
"licenses": [
"mit"
],
"is_license_text": true,
"is_license_notice": false,
"is_license_reference": false,
"is_license_tag": false
}
}
],
"license_expressions": [
"mit"
],
"holders": [],
"copyrights": [],
"authors": [],
"is_legal": false,
"is_manifest": false,
"is_readme": true,
"is_top_level": true,
"is_key_file": true,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
},
{
"path": "basic/index.js",
"type": "file",
"name": "index.js",
"base_name": "index",
"extension": ".js",
"size": 2109,
"date": "2018-10-29",
"sha1": "1ef59e75d33ed8b7b43548fd55843d894db4b910",
"md5": "1385905becfdfd8d777342fcb1242d83",
"mime_type": "text/plain",
"file_type": "ASCII text",
"programming_language": "JavaScript",
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_media": false,
"is_source": true,
"is_script": false,
"licenses": [
{
"key": "mit",
"score": 100.0,
"name": "MIT License",
"short_name": "MIT License",
"category": "Permissive",
"is_exception": false,
"owner": "MIT",
"homepage_url": "http://opensource.org/licenses/mit-license.php",
"text_url": "http://opensource.org/licenses/mit-license.php",
"reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:mit",
"spdx_license_key": "MIT",
"spdx_url": "https://spdx.org/licenses/MIT",
"start_line": 2,
"end_line": 19,
"matched_rule": {
"identifier": "mit.LICENSE",
"license_expression": "mit",
"licenses": [
"mit"
],
"is_license_text": true,
"is_license_notice": false,
"is_license_reference": false,
"is_license_tag": false
}
}
],
"license_expressions": [
"mit"
],
"holders": [
{
"value": "nexB Inc.",
"start_line": 1,
"end_line": 1
}
],
"copyrights": [
{
"value": "Copyright (c) 2007 nexB Inc.",
"start_line": 1,
"end_line": 1
}
],
"authors": [],
"is_legal": false,
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
},
{
"path": "basic/package.json",
"type": "file",
"name": "package.json",
"base_name": "package",
"extension": ".json",
"size": 829,
"date": "2017-08-29",
"sha1": "003103b742ebfb1e76e80d9fc05ab0b3046f2ab6",
"md5": "bd8911e2d8af0caa689f76b9975761fd",
"mime_type": "text/plain",
"file_type": "ASCII text",
"programming_language": null,
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"licenses": [
{
"key": "mit",
"score": 99.0,
"name": "MIT License",
"short_name": "MIT License",
"category": "Permissive",
"is_exception": false,
"owner": "MIT",
"homepage_url": "http://opensource.org/licenses/mit-license.php",
"text_url": "http://opensource.org/licenses/mit-license.php",
"reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:mit",
"spdx_license_key": "MIT",
"spdx_url": "https://spdx.org/licenses/MIT",
"start_line": 7,
"end_line": 7,
"matched_rule": {
"identifier": "mit_34.RULE",
"license_expression": "mit",
"licenses": [
"mit"
],
"is_license_text": false,
"is_license_notice": false,
"is_license_reference": false,
"is_license_tag": true
}
}
],
"license_expressions": [
"mit"
],
"holders": [],
"copyrights": [],
"authors": [],
"is_legal": false,
"is_manifest": true,
"is_readme": false,
"is_top_level": true,
"is_key_file": true,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
}
]
}
36 changes: 36 additions & 0 deletions tests/summarycode/data/score/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# @invisionag/eslint-config-ivx

# Usage

Install the peer dependencies as development dependencies:
- `eslint^3.19.0`
- `prettier^1.5.2`

Install `@invisionag/eslint-config-ivx` as a development dependency.

In your `.eslintrc.js`:
```js
module.exports = {
extends: '@invisionag/ivx',
};
```


Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
74 changes: 74 additions & 0 deletions tests/summarycode/data/score/basic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Copyright (c) 2007 nexB Inc. All right reserved
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module.exports = {
extends: [
'airbnb',
'prettier',
'prettier/flowtype',
'prettier/react',
'plugin:flowtype/recommended',
],
parser: 'babel-eslint',
plugins: ['prettier', 'flowtype', 'react-functional-set-state'],
env: {
browser: true,
node: true,
jest: true,
},
rules: {
'no-undef-init': 1,
'react/sort-comp': [
1,
{
order: [
'type-annotations',
'static-methods',
'lifecycle',
'everything-else',
'render',
],
groups: {
rendering: ['/^render.+$/', 'render'],
},
},
],
'react/jsx-filename-extension': [
1,
{
extensions: ['.js'],
},
],
'react-functional-set-state/no-this-state-props': 2,
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
},
],
'prettier/prettier': [
'error',
{
trailingComma: 'all',
singleQuote: true,
},
],
},
};
Loading

0 comments on commit 3e6b628

Please sign in to comment.