Skip to content

Commit

Permalink
Link with customFormat
Browse files Browse the repository at this point in the history
- Only trigger COPYRIGHT parser when configured.
- Fix code analysis.
  • Loading branch information
zodiac403 committed Mar 30, 2018
1 parent f83aaae commit 9cb45f2
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var flatten = function(options) {

// Include property in output unless custom format has set property to false.
var include = function(property) {
return true; // (options.customFormat === undefined || options.customFormat[property] !== false);
return options.customFormat === undefined || options.customFormat[property] !== false;
};

if (include("repository") && json.repository) {
Expand Down Expand Up @@ -178,7 +178,7 @@ var flatten = function(options) {
}

if (index === 0) {
// Treat the file with the highest precedense as licenseFile
// Treat the file with the highest precedence as licenseFile
/*istanbul ignore else*/
if (include("licenseFile")) {
moduleInfo.licenseFile = options.basePath ? path.relative(options.basePath, licenseFile) : licenseFile;
Expand All @@ -196,30 +196,30 @@ var flatten = function(options) {
}
}

if (!content) {
content = fs.readFileSync(licenseFile, { encoding: 'utf8' });
}
if(include('copyright') && options.customFormat) {
if (!content) {
content = fs.readFileSync(licenseFile, { encoding: 'utf8' });
}

var linesWithCopyright = content
var linesWithCopyright = content
.split('\n')
.filter(function(value) {
return value.startsWith('opyright', 1) && // include copyright statements
!value.startsWith('opyright notice', 1); // exclude lines from from license text.
!value.startsWith('opyright notice', 1); // exclude lines from from license text
})
.filter(function(value, index, list) {
return index === 0 || value !== list[0]; // remove identical duplicates
});

if(linesWithCopyright.length > 0) {
moduleInfo.copyright = linesWithCopyright[0].trim();
}

// Mark files with multiple copyright
// statements. This might be an
// indicator to take a closer look in
// the LICENSE file.
if(linesWithCopyright.length > 1) {
moduleInfo.copyright += '*';
if(linesWithCopyright.length > 0) {
moduleInfo.copyright = linesWithCopyright[0].trim();
}

// Mark files with multiple copyright statements. This might be
// an indicator to take a closer look at the LICENSE file.
if(linesWithCopyright.length > 1) {
moduleInfo.copyright += '*';
}
}
}
}
Expand Down

0 comments on commit 9cb45f2

Please sign in to comment.