Skip to content

Commit

Permalink
fix(lint): notify about version differences for eslint-plugin-esl
Browse files Browse the repository at this point in the history
Co-authored-by: ala'n (Alexey Stsefanovich) <astsefanovich@exadel.com>
  • Loading branch information
fshovchko and ala-n committed Jun 10, 2024
1 parent 8e376cc commit 4cc0ddc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"clean": "rimraf dist",
"build": "npm run clean && tsc --project tsconfig.build.json"
},
"dependencies": {},
"dependencies": {
"semver": "^7.6.2"
},
"files": [
"dist/**/*"
],
Expand Down
25 changes: 25 additions & 0 deletions eslint/src/core/check-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {lt} from 'semver';
import color from 'kleur';

const ESL_PACKAGE = '@exadel/esl';
const PLUGIN_PACKAGE = '@exadel/eslint-plugin-esl';

function getInstalledVersion(packageName: string): string | null {
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
return require(`${packageName}/package.json`).version;
} catch (error) {
return null;
}
}

export function checkVersion(): void {
const eslintVersion = getInstalledVersion(PLUGIN_PACKAGE);
const eslVersion = getInstalledVersion(ESL_PACKAGE);
if (!(eslintVersion && eslVersion && lt(eslintVersion, eslVersion))) return;

console.log(`\n${color.yellow('⚠️ Warning:')}
Your installed version of ${color.yellow(PLUGIN_PACKAGE)} (${color.red(eslintVersion)}) \
is lower than version of main package ${color.yellow(ESL_PACKAGE)} (${color.green(eslVersion)}).
Please update ${color.yellow(PLUGIN_PACKAGE)} to the latest version ${color.green(eslVersion)}\n`);
}
3 changes: 3 additions & 0 deletions eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import DEPRECATED_4_RULES from './rules/4/all.rules';
import DEPRECATED_5_RULES from './rules/5/all.rules';
import {checkVersion} from './core/check-version';

import type {Rule} from 'eslint';

export type logLevel = 'warn' | 'error';

checkVersion();

const buildDefault = (definition: Record<string, Rule.RuleModule>, level: logLevel): Record<string, logLevel> => {
const config: Record<string, logLevel> = {};
for (const name of Object.keys(definition)) {
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4cc0ddc

Please sign in to comment.