-
-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support isolated folder for monorepo #628
Open
hanzhangyu
wants to merge
3
commits into
kucherenko:master
Choose a base branch
from
hanzhangyu:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {detectClones} from "jscpd"; | ||
|
||
(async () => { | ||
const clones = await detectClones({ | ||
path: [ | ||
__dirname + '/../fixtures' | ||
], | ||
skipIsolated: [ | ||
['packages/businessA', 'packages/businessB', 'packages/businessC'], | ||
], | ||
silent: true | ||
}); | ||
console.log(clones); | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copy the size of snapshot frame "sn" to frame "fr". Do the same for all | ||
* following frames and children. | ||
* Returns a pointer to the old current window, or NULL. | ||
*/ | ||
static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr) | ||
{ | ||
win_T *wp = NULL; | ||
win_T *wp2; | ||
|
||
fr->fr_height = sn->fr_height; | ||
fr->fr_width = sn->fr_width; | ||
if (fr->fr_layout == FR_LEAF) { | ||
frame_new_height(fr, fr->fr_height, FALSE, FALSE); | ||
frame_new_width(fr, fr->fr_width, FALSE, FALSE); | ||
wp = sn->fr_win; | ||
} | ||
win_T *wp = NULL; | ||
win_T *wp2; | ||
|
||
fr->fr_height = sn->fr_height; | ||
fr->fr_width = sn->fr_width; | ||
if (fr->fr_layout == FR_LEAF) { | ||
frame_new_height(fr, fr->fr_height, FALSE, FALSE); | ||
frame_new_width(fr, fr->fr_width, FALSE, FALSE); | ||
wp = sn->fr_win; | ||
} | ||
return wp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
*12312 | ||
*/ | ||
function utf8_encode ( str_data ) { | ||
// Encodes an ISO-8859-1 string to UTF-8 | ||
// | ||
// + original by: Webtoolkit.info (http://www.webtoolkit.info/) | ||
str_data = str_data.replace(/\r\n/g,"\n"); | ||
var utftext = ""; | ||
|
||
for (var n = 0; n < str_data.length; n++) { | ||
var c = str_data.charCodeAt(n); | ||
if (c < 128) { | ||
utftext += String.fromCharCode(c); | ||
} else if((c > 127) && (c < 2048)) { | ||
utftext += String.fromCharCode((c >> 6) | 192); | ||
utftext += String.fromCharCode((c & 63) | 128); | ||
} else { | ||
utftext += String.fromCharCode((c >> 12) | 224); | ||
utftext += String.fromCharCode(((c >> 6) & 63) | 128); | ||
utftext += String.fromCharCode((c & 63) | 128); | ||
} | ||
} | ||
|
||
return utftext; | ||
} | ||
|
||
module.exports = function (store) { | ||
function getset (name, value) { | ||
var node = vars.store; | ||
var keys = name.split('.'); | ||
keys.slice(0,-1).forEach(function (k) { | ||
if (node[k] === undefined) node[k] = {}; | ||
node = node[k] | ||
}); | ||
var key = keys[keys.length - 1]; | ||
if (arguments.length == 1) { | ||
return node[key]; | ||
} | ||
else { | ||
return node[key] = value; | ||
} | ||
} | ||
|
||
var vars = { | ||
get : function (name) { | ||
return getset(name); | ||
}, | ||
set : function (name, value) { | ||
return getset(name, value); | ||
}, | ||
store : store || {}, | ||
}; | ||
return vars; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module.exports = function (store) { | ||
function getset (name, value) { | ||
var node = vars.store; | ||
var keys = name.split('.'); | ||
keys.slice(0,-1).forEach(function (k) { | ||
if (node[k] === undefined) node[k] = {}; | ||
node = node[k] | ||
}); | ||
var key = keys[keys.length - 1]; | ||
if (arguments.length == 1) { | ||
return node[key]; | ||
} | ||
else { | ||
return node[key] = value; | ||
} | ||
} | ||
|
||
var vars = { | ||
get : function (name) { | ||
return getset(name); | ||
}, | ||
set : function (name, value) { | ||
return getset(name, value); | ||
}, | ||
store : store || {}, | ||
}; | ||
return vars; | ||
}; | ||
module.exports = function (store) { | ||
function getset (name, value) { | ||
var node = vars.store; | ||
var keys = name.split('.'); | ||
keys.slice(0,-1).forEach(function (k) { | ||
if (node[k] === undefined) node[k] = {}; | ||
node = node[k] | ||
}); | ||
var key = keys[keys.length - 1]; | ||
if (arguments.length == 1) { | ||
return node[key]; | ||
} | ||
else { | ||
return node[key] = value; | ||
} | ||
} | ||
|
||
var vars = { | ||
get : function (name) { | ||
return getset(name); | ||
}, | ||
set : function (name, value) { | ||
return getset(name, value); | ||
}, | ||
store : store || {}, | ||
}; | ||
return vars; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './skip-local.validator'; | ||
export * from './skip-isolated.validator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {getOption, IClone, ICloneValidator, IOptions, IValidationResult} from '@jscpd/core'; | ||
import {isAbsolute, relative} from "path"; | ||
|
||
export class SkipIsolatedValidator implements ICloneValidator { | ||
isRelativeMemoMap = new Map(); | ||
|
||
|
||
validate(clone: IClone, options: IOptions): IValidationResult { | ||
const status = !this.shouldSkipClone(clone, options); | ||
return { | ||
status, | ||
clone, | ||
message: [ | ||
`Sources of duplication located in isolated folder (${clone.duplicationA.sourceId}, ${clone.duplicationB.sourceId})` | ||
] | ||
}; | ||
} | ||
|
||
public shouldSkipClone(clone: IClone, options: IOptions): boolean { | ||
const skipIsolatedPathList: string[][] = getOption('skipIsolated', options); | ||
return skipIsolatedPathList.some( | ||
(dirList) => { | ||
const relA = dirList.find(dir => this.isRelativeMemo(clone.duplicationA.sourceId, dir)); | ||
const relB = dirList.find(dir => this.isRelativeMemo(clone.duplicationB.sourceId, dir)); | ||
return relA && relB && relA !== relB | ||
} | ||
); | ||
} | ||
|
||
private isRelativeMemo(file: string, dir: string) { | ||
const memoKey = `${file},${dir}`; | ||
if (this.isRelativeMemoMap.has(memoKey)) return this.isRelativeMemoMap.get(memoKey); | ||
const isRel = SkipIsolatedValidator.isRelative(file, dir) | ||
this.isRelativeMemoMap.set(memoKey, isRel); | ||
return isRel; | ||
} | ||
|
||
private static isRelative(file: string, path: string): boolean { | ||
const rel = relative(path, file); | ||
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR, it is a brilliant idea!
May I suggest some changes, we have a similar option named
--skipLocal
for show duplications across the folders, the--skipLocal
usedpath
array from options to define folders, I guess we should use the same way here, what do you think?The result will be like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kucherenko Thank you for your advice. Sorry, I didn't describe it clearly.
--skipIsolated means that submodules (packages/businessA, packages/businessB etc) can be isolated from each other when the detect path is the monorepo home project. And, other folders still want to be included in the clone code statistics normally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, sounds good, will merge the PR and publish new version