How to use jscpd - 6 common examples

To help you get started, we’ve selected a few jscpd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xcatliu / cqc / src / JscpdChecker / jscpdReporter.js View on Github external
function reporterOrigin(options) {
    // Calling the origin reporter
    const jsonReporterResult = jsonReporter.call(this, options);
    const percentage = this.map.getPercentage();
    const limit = options.limit;

    // The log is the third args of the return array, which will output to the stdout
    const log = getPercentageLog({
        percentage,
        limit
    });

    if (percentage > limit) {
        // If the percentage is greater than limit, then we just output the log and exit the process. Keep the logic same with _std-log.coffee
        console.error(log);
        process.exit(1);
    }

    // The first one is the output json
github xcatliu / cqc / src / JscpdChecker / jscpdReporter.js View on Github external
function jscpdReporter(options) {
    // Pass filterFiles option will enhance the result with an extro property: filterDuplicates
    const filterFiles = options.filterFiles;
    // If no filterFiles is passed, then we just return the origin report with our custom logger
    if (typeof filterFiles === 'undefined' || filterFiles.length === 0) {
        return reporterOrigin.call(this, options);
    }

    // Calling the origin reporter and add an extro property filterDuplicates
    const jsonReporterResult = jsonReporter.call(this, options);

    // Get the filterClones
    const filterClones = this.map.clones.filter(({ firstFile, secendFile }) => {
        for (let i = 0; i < filterFiles.length; i++) {
            // If the filepath is same, then return true
            if (filterFiles[i] === firstFile || filterFiles[i] === secendFile) {
                return true;
            }
        }
        return false;
    });

    const filterDuplicates = filterClones.map((clone) => {
        // Keep the structure same with duplicates property
        return {
            lines: clone.linesCount,
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / codeDuplication.ts View on Github external
switchMap(async () => {
                StoresManager.close()
                StoresManager.flush()
                const cpd = new JSCPD({})
                const clones: IClone[] = []
                for (const doc of docs) {
                    clones.push(...(await cpd.detect(doc.text, { id: doc.uri, format: jscpdFormat(doc) })))
                }
                const diagnostics: sourcegraph.Diagnostic[] = clones.map(c => {
                    const numLines = c.duplicationA.end.line - c.duplicationA.start.line
                    return {
                        resource: new URL(c.duplicationA.sourceId),
                        range: duplicationRange(c.duplicationA),
                        message: `Duplicated code (${numLines} line${numLines !== 1 ? 's' : ''})`,
                        source: 'codeDuplication',
                        severity: sourcegraph.DiagnosticSeverity.Information,
                        relatedInformation: [
                            {
                                location: new sourcegraph.Location(
                                    new URL(c.duplicationB.sourceId),
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / codeDuplication.ts View on Github external
switchMap(async () => {
                StoresManager.close()
                StoresManager.flush()
                const cpd = new JSCPD({})
                const clones: IClone[] = []
                for (const doc of docs) {
                    clones.push(...(await cpd.detect(doc.text, { id: doc.uri, format: jscpdFormat(doc) })))
                }
                const diagnostics: sourcegraph.Diagnostic[] = clones.map(c => {
                    const numLines = c.duplicationA.end.line - c.duplicationA.start.line
                    return {
                        resource: new URL(c.duplicationA.sourceId),
                        range: duplicationRange(c.duplicationA),
                        message: `Duplicated code (${numLines} line${numLines !== 1 ? 's' : ''})`,
                        source: 'codeDuplication',
                        severity: sourcegraph.DiagnosticSeverity.Information,
                        relatedInformation: [
                            {
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / codeDuplication.ts View on Github external
switchMap(async () => {
                StoresManager.close()
                StoresManager.flush()
                const cpd = new JSCPD({})
                const clones: IClone[] = []
                for (const doc of docs) {
                    clones.push(...(await cpd.detect(doc.text, { id: doc.uri, format: jscpdFormat(doc) })))
                }
                const diagnostics: sourcegraph.Diagnostic[] = clones.map(c => {
                    const numLines = c.duplicationA.end.line - c.duplicationA.start.line
                    return {
                        resource: new URL(c.duplicationA.sourceId),
                        range: duplicationRange(c.duplicationA),
                        message: `Duplicated code (${numLines} line${numLines !== 1 ? 's' : ''})`,
                        source: 'codeDuplication',
                        severity: sourcegraph.DiagnosticSeverity.Information,
                        relatedInformation: [
                            {
                                location: new sourcegraph.Location(
github xcatliu / cqc / src / JscpdChecker / getLanguageFromFilepath.js View on Github external
const path = require('path');

const TokenizerFactory = require('jscpd/lib/tokenizer/TokenizerFactory');

const languageToExtentionMap = TokenizerFactory.prototype.LANGUAGES;
const extensionToLanguageMap = {};

Object.keys(languageToExtentionMap).forEach((language) => {
    languageToExtentionMap[language].forEach((extention) => {
        extensionToLanguageMap[extention] = language;
    });
});

module.exports = function getLanguageFromFilepath(filepath) {
    const extension = path.extname(filepath).slice(1);
    const result = extensionToLanguageMap[extension];
    if (typeof result === 'undefined') {
        return 'js';
    }
    return result;
};

jscpd

detector of copy/paste in files

MIT
Latest version published 7 months ago

Package Health Score

75 / 100
Full package analysis

Similar packages