New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@eclipse-glsp/cli

Package Overview
Dependencies
Maintainers
6
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eclipse-glsp/cli - npm Package Compare versions

Comparing version 2.1.0-next.e32e40e.153 to 2.2.0-next.886d2d0.156

8

lib/commands/check-header.d.ts

@@ -8,8 +8,5 @@ export interface HeaderCheckOptions {

autoFix: boolean;
severity: Severity;
}
declare const checkTypes: readonly ["full", "changes", "lastCommit"];
type CheckType = typeof checkTypes[number];
declare const severityTypes: readonly ["error", "warn", "ok"];
type Severity = typeof severityTypes[number];
type CheckType = (typeof checkTypes)[number];
export declare const CheckHeaderCommand: import("commander").Command;

@@ -20,7 +17,6 @@ export declare function checkHeaders(rootDir: string, options: HeaderCheckOptions): void;

file: string;
severity: Severity;
violation: Violation;
}
type Violation = 'none' | 'noOrMissingHeader' | 'incorrectCopyrightPeriod' | 'invalidCopyrightYear';
type Violation = 'none' | 'noOrMissingHeader' | 'invalidEndYear';
export {};
//# sourceMappingURL=check-header.d.ts.map

@@ -55,10 +55,9 @@ "use strict";

const checkTypes = ['full', 'changes', 'lastCommit'];
const severityTypes = ['error', 'warn', 'ok'];
const DEFAULT_EXCLUDES = ['**/@(node_modules|lib|dist|bundle)/**'];
const YEAR_RANGE_REGEX = /\d{4}(?:-d{4})?/g;
const HEADER_PATTERN = 'Copyright \\([cC]\\) \\d{4}(-d{4})?';
const YEAR_RANGE_REGEX = /\d{4}/g;
const HEADER_PATTERN = 'Copyright \\([cC]\\) \\d{4}';
const AUTO_FIX_MESSAGE = 'Fix copyright header violations';
exports.CheckHeaderCommand = (0, command_util_1.baseCommand)() //
.name('checkHeaders')
.description('Validates the copyright year range of license header files')
.description('Validates the copyright year range (end year) of license header files')
.argument('<rootDir>', 'The starting directory for the check', validation_util_1.validateGitDirectory)

@@ -73,5 +72,2 @@ .addOption(new commander_1.Option('-t, --type <type>', 'The scope of the check. In addition to a full recursive check, is also possible to only' +

.option('-j, --json', 'Also persist validation results as json file', false)
.addOption(new commander_1.Option('-s, --severity <severity>', 'The severity of validation results that should be printed.')
.choices(severityTypes)
.default('error', '"error" (only)'))
.option('-a, --autoFix', 'Auto apply & commit fixes without prompting the user', false)

@@ -113,9 +109,4 @@ .action(checkHeaders);

var _a;
// Derives all files with valid headers, their copyright years and all files with no or invalid headers
// Derives all files with valid headers and all files with no or invalid headers
const filesWithHeader = sh.grep('-l', HEADER_PATTERN, files).stdout.trim().split('\n');
const copyrightYears = sh
.grep(HEADER_PATTERN, files)
.stdout.trim()
.split('\n')
.map(line => line.match(YEAR_RANGE_REGEX).map(string => Number.parseInt(string, 10)));
const noHeaders = files.filter(file => !filesWithHeader.includes(file));

@@ -131,3 +122,3 @@ const results = [];

printFileProgress(i + 1, allFilesLength, `Validating ${file}`);
results.push({ file: path.resolve(rootDir, file), violation: 'noOrMissingHeader', severity: 'error' });
results.push({ file: path.resolve(rootDir, file), violation: 'noOrMissingHeader' });
});

@@ -145,17 +136,14 @@ // Performance optimization: avoid retrieving the dates for each individual file by precalculating the endYear if possible.

printFileProgress(i + 1 + noHeadersLength, allFilesLength, `Validating ${file}`);
const copyrightLine = sh.head({ '-n': 2 }, file).stdout.trim().split('\n')[1];
const copyRightYears = copyrightLine.match(YEAR_RANGE_REGEX);
const currentStartYear = Number.parseInt(copyRightYears[0], 10);
const currentEndYear = copyRightYears[1] ? Number.parseInt(copyRightYears[1], 10) : undefined;
const result = {
currentStartYear: copyrightYears[i].shift(),
expectedStartYear: (0, git_util_1.getFirstModificationDate)(file, rootDir, AUTO_FIX_MESSAGE).getFullYear(),
currentEndYear: copyrightYears[i].shift(),
currentStartYear,
currentEndYear,
expectedEndYear: defaultEndYear !== null && defaultEndYear !== void 0 ? defaultEndYear : (0, git_util_1.getLastModificationDate)(file, rootDir, AUTO_FIX_MESSAGE).getFullYear(),
file,
severity: 'ok',
violation: 'none'
};
if (result.expectedStartYear === result.expectedEndYear) {
validateSingleYear(result);
}
else {
validateTimePeriod(result);
}
validateEndYear(result);
results.push(result);

@@ -167,49 +155,10 @@ });

}
function validateSingleYear(result) {
const { currentStartYear, expectedStartYear, currentEndYear } = result;
result.violation = 'invalidCopyrightYear';
result.severity = 'error';
if (!currentEndYear) {
if (currentStartYear === expectedStartYear) {
result.violation = 'none';
result.severity = 'ok';
}
return;
}
// Cornercase: For files of the initial contribution the copyright header predates the first git modification date.
// => declare as warning if not part of the initial contribution.
if (expectedStartYear === currentEndYear && currentStartYear < expectedStartYear) {
if ((0, git_util_1.getFirstCommit)(result.file) === (0, git_util_1.getInitialCommit)()) {
result.violation = 'none';
result.severity = 'ok';
}
else {
result.severity = 'warn';
}
}
}
function validateTimePeriod(result) {
const { currentStartYear, expectedStartYear, expectedEndYear, currentEndYear } = result;
result.violation = 'incorrectCopyrightPeriod';
result.severity = 'error';
if (!currentEndYear) {
result.severity = 'error';
return;
}
if (currentStartYear === expectedStartYear && currentEndYear === expectedEndYear) {
function validateEndYear(result) {
const { currentStartYear, expectedEndYear, currentEndYear } = result;
result.violation = 'invalidEndYear';
const valid = currentEndYear ? currentEndYear === expectedEndYear : currentStartYear === expectedEndYear;
if (valid) {
result.violation = 'none';
result.severity = 'ok';
return;
}
// Cornercase: For files of the initial contribution the copyright header predates the first git modification date.
// => declare as warning if not part of the initial contribution.
if (currentEndYear === expectedEndYear && currentStartYear < expectedEndYear) {
if ((0, git_util_1.getFirstCommit)(result.file) === (0, git_util_1.getInitialCommit)()) {
result.violation = 'none';
result.severity = 'ok';
}
else {
result.severity = 'warn';
}
}
}

@@ -229,11 +178,5 @@ function printFileProgress(currentFileCount, maxFileCount, message, clear = true) {

logger_1.LOGGER.info(`Header validation for ${results.length} files completed`);
const violations = results.filter(result => result.severity === 'error');
const violations = results.filter(result => result.violation !== 'none');
// Adjust results to print based on configured severity level
let toPrint = results;
if (options.severity === 'error') {
toPrint = violations;
}
else if (options.severity === 'warn') {
toPrint = results.filter(result => result.severity !== 'ok');
}
const toPrint = violations;
logger_1.LOGGER.info(`Found ${toPrint.length} copyright header violations:`);

@@ -247,3 +190,3 @@ logger_1.LOGGER.newLine();

if (violations.length > 0 && (options.autoFix || readline.keyInYN('Do you want automatically fix copyright year range violations?'))) {
const toFix = violations.filter(violation => violation.severity === 'error' && isDateValidationResult(violation));
const toFix = violations.filter(violation => isDateValidationResult(violation));
fixViolations(rootDir, toFix, options);

@@ -255,20 +198,16 @@ }

function toPrintMessage(result) {
const colors = {
error: '\x1b[31m',
warn: '\x1b[33m',
ok: '\x1b[32m'
};
if (isDateValidationResult(result) &&
(result.violation === 'incorrectCopyrightPeriod' || result.violation === 'invalidCopyrightYear')) {
const expected = result.expectedStartYear !== result.expectedEndYear
? `${result.expectedStartYear}-${result.expectedEndYear}`
: result.expectedStartYear.toString();
const actual = result.currentEndYear ? `${result.currentStartYear}-${result.currentEndYear}` : result.currentStartYear.toString();
const message = result.violation === 'incorrectCopyrightPeriod' ? 'Invalid copyright period' : 'Invalid copyright year';
return `${colors[result.severity]} ${message}! Expected '${expected}' but is '${actual}'`;
const error = '\x1b[31m';
const info = '\x1b[32m';
if (isDateValidationResult(result) && result.violation === 'invalidEndYear') {
const expected = result.expectedEndYear.toString();
const actual = result.currentEndYear
? `${result.currentEndYear} (${result.currentStartYear}-${result.currentEndYear})`
: result.currentStartYear.toString();
const message = 'Invalid copyright end year';
return `${error} ${message}! Expected end year '${expected}' but is '${actual}'`;
}
else if (result.violation === 'noOrMissingHeader') {
return `${colors[result.severity]} No or invalid copyright header!`;
return `${error} No or invalid copyright header!`;
}
return `${colors[result.severity]} OK`;
return `${info} OK`;
}

@@ -279,8 +218,6 @@ function fixViolations(rootDir, violations, options) {

printFileProgress(i + 1, violations.length, `Fix ${violation.file}`, false);
const fixedStartYear = violation.currentStartYear < violation.expectedStartYear ? violation.currentStartYear : violation.expectedStartYear;
const currentRange = `${violation.currentStartYear}${violation.currentEndYear ? '-' + violation.currentEndYear : ''}`;
let fixedRange = `${fixedStartYear}`;
if (violation.expectedEndYear !== violation.expectedStartYear || fixedStartYear !== violation.expectedStartYear) {
fixedRange = `${fixedStartYear}-${violation.expectedEndYear}`;
}
const fixedRange = violation.currentEndYear || violation.currentStartYear < violation.expectedEndYear
? `${violation.currentStartYear}-${violation.expectedEndYear}`
: `${violation.expectedEndYear}`;
sh.sed('-i', RegExp('Copyright \\([cC]\\) ' + currentRange), `Copyright (c) ${fixedRange}`, violation.file);

@@ -298,4 +235,4 @@ });

function isDateValidationResult(object) {
return 'currentStartYear' in object && 'expectedStartYear' in object && 'expectedEndYear' in object;
return 'currentStartYear' in object && 'expectedEndYear' in object;
}
//# sourceMappingURL=check-header.js.map

@@ -64,3 +64,3 @@ "use strict";

sh.cd(REPO_ROOT);
(0, common_1.updateVersion)({ name: '@eclipse-glsp/protocol', version }, { name: '@eclipse-glsp/client', version }, { name: '@eclipse-glsp-examples/workflow-glsp', version }, { name: '@eclipse-glsp-examples/workflow-server', version });
(0, common_1.updateVersion)({ name: '@eclipse-glsp/protocol', version }, { name: '@eclipse-glsp/client', version }, { name: '@eclipse-glsp-examples/workflow-glsp', version }, { name: '@eclipse-glsp-examples/workflow-server', version }, { name: '@eclipse-glsp-examples/workflow-server-bundled', version });
}

@@ -67,0 +67,0 @@ function build() {

@@ -37,23 +37,3 @@ /********************************************************************************

export declare function getLastModificationDate(filePath?: string, repoRoot?: string, excludeMessage?: string): Date | undefined;
/**
* Returns the last modification date of a file in a git repo.
* @param filePath The file
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
* @param excludeMessage Only consider commits that don`t match the excludeMessage
* @returns The date or undefined if the file is outside of the git repo.
*/
export declare function getFirstModificationDate(filePath: string, repoRoot?: string, excludeMessage?: string): Date | undefined;
export declare function getFilesOfCommit(commitHash: string, repoRoot?: string): string[];
/**
* Returns the commit hash of the initial commit of the given repository
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
* @returns The commit hash or undefined if something went wrong.
*/
export declare function getInitialCommit(repoRoot?: string): string | undefined;
/**
* Returns the commit hash of the first commit for a given file (across renames).
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
* @returns The commit hash or undefined if something went wrong.
*/
export declare function getFirstCommit(filePath: string, repoRoot?: string): string | undefined;
export declare function getLatestGithubRelease(path?: string): string;

@@ -60,0 +40,0 @@ export declare function getLatestTag(path?: string): string;

@@ -41,3 +41,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getRemoteUrl = exports.hasBranch = exports.getLatestTag = exports.getLatestGithubRelease = exports.getFirstCommit = exports.getInitialCommit = exports.getFilesOfCommit = exports.getFirstModificationDate = exports.getLastModificationDate = exports.getChangesOfLastCommit = exports.getUncommittedChanges = exports.hasGitChanges = exports.getGitRoot = exports.isGitRepository = void 0;
exports.getRemoteUrl = exports.hasBranch = exports.getLatestTag = exports.getLatestGithubRelease = exports.getFilesOfCommit = exports.getLastModificationDate = exports.getChangesOfLastCommit = exports.getUncommittedChanges = exports.hasGitChanges = exports.getGitRoot = exports.isGitRepository = void 0;
const path_1 = require("path");

@@ -111,24 +111,2 @@ const sh = __importStar(require("shelljs"));

exports.getLastModificationDate = getLastModificationDate;
/**
* Returns the last modification date of a file in a git repo.
* @param filePath The file
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
* @param excludeMessage Only consider commits that don`t match the excludeMessage
* @returns The date or undefined if the file is outside of the git repo.
*/
function getFirstModificationDate(filePath, repoRoot, excludeMessage) {
cdIfPresent(repoRoot);
const additionalArgs = excludeMessage ? `--grep="${excludeMessage}" --invert-grep` : '';
const result = sh.exec(`git log ${additionalArgs} --pretty="format:%ci" --follow ${filePath}`, (0, command_util_1.getShellConfig)());
if (result.code !== 0) {
return undefined;
}
const datesString = result.stdout.trim();
if (datesString.length === 0) {
return new Date();
}
const date = datesString.split('\n').pop();
return date ? new Date(date) : undefined;
}
exports.getFirstModificationDate = getFirstModificationDate;
function getFilesOfCommit(commitHash, repoRoot) {

@@ -143,34 +121,2 @@ cdIfPresent(repoRoot);

exports.getFilesOfCommit = getFilesOfCommit;
/**
* Returns the commit hash of the initial commit of the given repository
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
* @returns The commit hash or undefined if something went wrong.
*/
function getInitialCommit(repoRoot) {
cdIfPresent(repoRoot);
const result = sh.exec('git log --pretty=oneline --reverse', (0, command_util_1.getShellConfig)());
if (result.code !== 0) {
return undefined;
}
const commits = result.stdout.trim();
if (commits.length === 0) {
return undefined;
}
return commits.substring(0, commits.indexOf(' '));
}
exports.getInitialCommit = getInitialCommit;
/**
* Returns the commit hash of the first commit for a given file (across renames).
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
* @returns The commit hash or undefined if something went wrong.
*/
function getFirstCommit(filePath, repoRoot) {
cdIfPresent(repoRoot);
const result = sh.exec(`git log --follow --pretty=format:"%H" ${filePath}`, (0, command_util_1.getShellConfig)());
if (result.code !== 0) {
return undefined;
}
return result.stdout.trim().split('\n').pop();
}
exports.getFirstCommit = getFirstCommit;
function getLatestGithubRelease(path) {

@@ -177,0 +123,0 @@ cdIfPresent(path);

{
"name": "@eclipse-glsp/cli",
"version": "2.1.0-next.e32e40e.153+e32e40e",
"version": "2.2.0-next.886d2d0.156+886d2d0",
"description": "CLI Tooling & scripts for GLSP components",

@@ -52,3 +52,3 @@ "keywords": [

"devDependencies": {
"@eclipse-glsp/config": "2.1.0-next.e32e40e.153+e32e40e",
"@eclipse-glsp/config": "2.2.0-next.886d2d0.156+886d2d0",
"@types/glob": "^8.1.0",

@@ -63,3 +63,3 @@ "@types/node-fetch": "^2.6.6",

},
"gitHead": "e32e40e1f6142ca867a8965325269b62f550f930"
"gitHead": "886d2d02687e28a6a6c243b96449f31b738a3c4e"
}

@@ -24,10 +24,3 @@ /********************************************************************************

import { baseCommand, configureShell, getShellConfig } from '../util/command-util';
import {
getChangesOfLastCommit,
getFirstCommit,
getFirstModificationDate,
getInitialCommit,
getLastModificationDate,
getUncommittedChanges
} from '../util/git-util';
import { getChangesOfLastCommit, getLastModificationDate, getUncommittedChanges } from '../util/git-util';

@@ -44,15 +37,10 @@ import { LOGGER } from '../util/logger';

autoFix: boolean;
severity: Severity;
}
const checkTypes = ['full', 'changes', 'lastCommit'] as const;
type CheckType = typeof checkTypes[number];
type CheckType = (typeof checkTypes)[number];
const severityTypes = ['error', 'warn', 'ok'] as const;
type Severity = typeof severityTypes[number];
const DEFAULT_EXCLUDES = ['**/@(node_modules|lib|dist|bundle)/**'];
const YEAR_RANGE_REGEX = /\d{4}(?:-d{4})?/g;
const HEADER_PATTERN = 'Copyright \\([cC]\\) \\d{4}(-d{4})?';
const YEAR_RANGE_REGEX = /\d{4}/g;
const HEADER_PATTERN = 'Copyright \\([cC]\\) \\d{4}';
const AUTO_FIX_MESSAGE = 'Fix copyright header violations';

@@ -62,3 +50,3 @@

.name('checkHeaders')
.description('Validates the copyright year range of license header files')
.description('Validates the copyright year range (end year) of license header files')
.argument('<rootDir>', 'The starting directory for the check', validateGitDirectory)

@@ -86,7 +74,2 @@ .addOption(

.option('-j, --json', 'Also persist validation results as json file', false)
.addOption(
new Option('-s, --severity <severity>', 'The severity of validation results that should be printed.')
.choices(severityTypes)
.default('error', '"error" (only)')
)
.option('-a, --autoFix', 'Auto apply & commit fixes without prompting the user', false)

@@ -134,13 +117,7 @@ .action(checkHeaders);

function validate(rootDir: string, files: string[], options: HeaderCheckOptions): ValidationResult[] {
// Derives all files with valid headers, their copyright years and all files with no or invalid headers
// Derives all files with valid headers and all files with no or invalid headers
const filesWithHeader = sh.grep('-l', HEADER_PATTERN, files).stdout.trim().split('\n');
const copyrightYears = sh
.grep(HEADER_PATTERN, files)
.stdout.trim()
.split('\n')
.map(line => line.match(YEAR_RANGE_REGEX)!.map(string => Number.parseInt(string, 10)));
const noHeaders = files.filter(file => !filesWithHeader.includes(file));
const results: ValidationResult[] = [];
const allFilesLength = files.length;

@@ -155,3 +132,3 @@

printFileProgress(i + 1, allFilesLength, `Validating ${file}`);
results.push({ file: path.resolve(rootDir, file), violation: 'noOrMissingHeader', severity: 'error' });
results.push({ file: path.resolve(rootDir, file), violation: 'noOrMissingHeader' });
});

@@ -170,18 +147,16 @@

printFileProgress(i + 1 + noHeadersLength, allFilesLength, `Validating ${file}`);
const copyrightLine = sh.head({ '-n': 2 }, file).stdout.trim().split('\n')[1];
const copyRightYears = copyrightLine.match(YEAR_RANGE_REGEX)!;
const currentStartYear = Number.parseInt(copyRightYears[0], 10);
const currentEndYear = copyRightYears[1] ? Number.parseInt(copyRightYears[1], 10) : undefined;
const result: DateValidationResult = {
currentStartYear: copyrightYears[i].shift()!,
expectedStartYear: getFirstModificationDate(file, rootDir, AUTO_FIX_MESSAGE)!.getFullYear(),
currentEndYear: copyrightYears[i].shift(),
currentStartYear,
currentEndYear,
expectedEndYear: defaultEndYear ?? getLastModificationDate(file, rootDir, AUTO_FIX_MESSAGE)!.getFullYear(),
file,
severity: 'ok',
violation: 'none'
};
if (result.expectedStartYear === result.expectedEndYear) {
validateSingleYear(result);
} else {
validateTimePeriod(result);
}
validateEndYear(result);
results.push(result);

@@ -196,53 +171,12 @@ });

function validateSingleYear(result: DateValidationResult): void {
const { currentStartYear, expectedStartYear, currentEndYear } = result;
result.violation = 'invalidCopyrightYear';
result.severity = 'error';
function validateEndYear(result: DateValidationResult): void {
const { currentStartYear, expectedEndYear, currentEndYear } = result;
result.violation = 'invalidEndYear';
if (!currentEndYear) {
if (currentStartYear === expectedStartYear) {
result.violation = 'none';
result.severity = 'ok';
}
return;
}
const valid = currentEndYear ? currentEndYear === expectedEndYear : currentStartYear === expectedEndYear;
// Cornercase: For files of the initial contribution the copyright header predates the first git modification date.
// => declare as warning if not part of the initial contribution.
if (expectedStartYear === currentEndYear && currentStartYear < expectedStartYear) {
if (getFirstCommit(result.file) === getInitialCommit()) {
result.violation = 'none';
result.severity = 'ok';
} else {
result.severity = 'warn';
}
}
}
function validateTimePeriod(result: DateValidationResult): void {
const { currentStartYear, expectedStartYear, expectedEndYear, currentEndYear } = result;
result.violation = 'incorrectCopyrightPeriod';
result.severity = 'error';
if (!currentEndYear) {
result.severity = 'error';
return;
}
if (currentStartYear === expectedStartYear && currentEndYear === expectedEndYear) {
if (valid) {
result.violation = 'none';
result.severity = 'ok';
return;
}
// Cornercase: For files of the initial contribution the copyright header predates the first git modification date.
// => declare as warning if not part of the initial contribution.
if (currentEndYear === expectedEndYear && currentStartYear < expectedEndYear) {
if (getFirstCommit(result.file) === getInitialCommit()) {
result.violation = 'none';
result.severity = 'ok';
} else {
result.severity = 'warn';
}
}
}

@@ -264,10 +198,5 @@

LOGGER.info(`Header validation for ${results.length} files completed`);
const violations = results.filter(result => result.severity === 'error');
const violations = results.filter(result => result.violation !== 'none');
// Adjust results to print based on configured severity level
let toPrint = results;
if (options.severity === 'error') {
toPrint = violations;
} else if (options.severity === 'warn') {
toPrint = results.filter(result => result.severity !== 'ok');
}
const toPrint = violations;

@@ -286,5 +215,3 @@ LOGGER.info(`Found ${toPrint.length} copyright header violations:`);

if (violations.length > 0 && (options.autoFix || readline.keyInYN('Do you want automatically fix copyright year range violations?'))) {
const toFix = violations.filter(
violation => violation.severity === 'error' && isDateValidationResult(violation)
) as DateValidationResult[];
const toFix = violations.filter(violation => isDateValidationResult(violation)) as DateValidationResult[];
fixViolations(rootDir, toFix, options);

@@ -297,24 +224,17 @@ }

function toPrintMessage(result: ValidationResult): string {
const colors: Record<Severity, string> = {
error: '\x1b[31m',
warn: '\x1b[33m',
ok: '\x1b[32m'
} as const;
const error = '\x1b[31m';
const info = '\x1b[32m';
if (
isDateValidationResult(result) &&
(result.violation === 'incorrectCopyrightPeriod' || result.violation === 'invalidCopyrightYear')
) {
const expected =
result.expectedStartYear !== result.expectedEndYear
? `${result.expectedStartYear}-${result.expectedEndYear}`
: result.expectedStartYear.toString();
const actual = result.currentEndYear ? `${result.currentStartYear}-${result.currentEndYear}` : result.currentStartYear.toString();
const message = result.violation === 'incorrectCopyrightPeriod' ? 'Invalid copyright period' : 'Invalid copyright year';
return `${colors[result.severity]} ${message}! Expected '${expected}' but is '${actual}'`;
if (isDateValidationResult(result) && result.violation === 'invalidEndYear') {
const expected = result.expectedEndYear.toString();
const actual = result.currentEndYear
? `${result.currentEndYear} (${result.currentStartYear}-${result.currentEndYear})`
: result.currentStartYear.toString();
const message = 'Invalid copyright end year';
return `${error} ${message}! Expected end year '${expected}' but is '${actual}'`;
} else if (result.violation === 'noOrMissingHeader') {
return `${colors[result.severity]} No or invalid copyright header!`;
return `${error} No or invalid copyright header!`;
}
return `${colors[result.severity]} OK`;
return `${info} OK`;
}

@@ -326,12 +246,9 @@

printFileProgress(i + 1, violations.length, `Fix ${violation.file}`, false);
const fixedStartYear =
violation.currentStartYear < violation.expectedStartYear ? violation.currentStartYear : violation.expectedStartYear;
const currentRange = `${violation.currentStartYear}${violation.currentEndYear ? '-' + violation.currentEndYear : ''}`;
const fixedRange =
violation.currentEndYear || violation.currentStartYear < violation.expectedEndYear
? `${violation.currentStartYear}-${violation.expectedEndYear}`
: `${violation.expectedEndYear}`;
let fixedRange = `${fixedStartYear}`;
if (violation.expectedEndYear !== violation.expectedStartYear || fixedStartYear !== violation.expectedStartYear) {
fixedRange = `${fixedStartYear}-${violation.expectedEndYear}`;
}
sh.sed('-i', RegExp('Copyright \\([cC]\\) ' + currentRange), `Copyright (c) ${fixedRange}`, violation.file);

@@ -352,3 +269,2 @@ });

file: string;
severity: Severity;
violation: Violation;

@@ -359,3 +275,2 @@ }

currentStartYear: number;
expectedStartYear: number;
currentEndYear?: number;

@@ -366,5 +281,5 @@ expectedEndYear: number;

function isDateValidationResult(object: ValidationResult): object is DateValidationResult {
return 'currentStartYear' in object && 'expectedStartYear' in object && 'expectedEndYear' in object;
return 'currentStartYear' in object && 'expectedEndYear' in object;
}
type Violation = 'none' | 'noOrMissingHeader' | 'incorrectCopyrightPeriod' | 'invalidCopyrightYear';
type Violation = 'none' | 'noOrMissingHeader' | 'invalidEndYear';

@@ -54,3 +54,4 @@ /********************************************************************************

{ name: '@eclipse-glsp-examples/workflow-glsp', version },
{ name: '@eclipse-glsp-examples/workflow-server', version }
{ name: '@eclipse-glsp-examples/workflow-server', version },
{ name: '@eclipse-glsp-examples/workflow-server-bundled', version }
);

@@ -57,0 +58,0 @@ }

@@ -87,25 +87,3 @@ /********************************************************************************

}
/**
* Returns the last modification date of a file in a git repo.
* @param filePath The file
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
* @param excludeMessage Only consider commits that don`t match the excludeMessage
* @returns The date or undefined if the file is outside of the git repo.
*/
export function getFirstModificationDate(filePath: string, repoRoot?: string, excludeMessage?: string): Date | undefined {
cdIfPresent(repoRoot);
const additionalArgs = excludeMessage ? `--grep="${excludeMessage}" --invert-grep` : '';
const result = sh.exec(`git log ${additionalArgs} --pretty="format:%ci" --follow ${filePath}`, getShellConfig());
if (result.code !== 0) {
return undefined;
}
const datesString = result.stdout.trim();
if (datesString.length === 0) {
return new Date();
}
const date = datesString.split('\n').pop();
return date ? new Date(date) : undefined;
}
export function getFilesOfCommit(commitHash: string, repoRoot?: string): string[] {

@@ -121,34 +99,2 @@ cdIfPresent(repoRoot);

/**
* Returns the commit hash of the initial commit of the given repository
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
* @returns The commit hash or undefined if something went wrong.
*/
export function getInitialCommit(repoRoot?: string): string | undefined {
cdIfPresent(repoRoot);
const result = sh.exec('git log --pretty=oneline --reverse', getShellConfig());
if (result.code !== 0) {
return undefined;
}
const commits = result.stdout.trim();
if (commits.length === 0) {
return undefined;
}
return commits.substring(0, commits.indexOf(' '));
}
/**
* Returns the commit hash of the first commit for a given file (across renames).
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
* @returns The commit hash or undefined if something went wrong.
*/
export function getFirstCommit(filePath: string, repoRoot?: string): string | undefined {
cdIfPresent(repoRoot);
const result = sh.exec(`git log --follow --pretty=format:"%H" ${filePath}`, getShellConfig());
if (result.code !== 0) {
return undefined;
}
return result.stdout.trim().split('\n').pop();
}
export function getLatestGithubRelease(path?: string): string {

@@ -155,0 +101,0 @@ cdIfPresent(path);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc