Skip to content

Commit

Permalink
feat(eslint-plugin): harmonize engines versions (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanot authored Jul 24, 2024
2 parents faa6e95 + dd6d6b2 commit 43f6e92
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ module.exports = {
'rules': {
'@o3r/json-dependency-versions-harmonize': ['error', {
ignoredPackages: ['@o3r/build-helpers'],
alignPeerDependencies: false
alignPeerDependencies: false,
alignEngines: true
}],
'@nx/dependency-checks': ['error', {
'buildTargets': ['build', 'build-builders', 'compile', 'test'],
Expand Down
1 change: 0 additions & 1 deletion packages/@ama-sdk/core/src/plugins/abort/abort.fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const isPromise = (result: boolean | void | Promise<void> | Promise<boolean>): r
* }
* );
* ```
*
* @example Abort on Timeout
* ```typescript
* const abortCondition: AbortCallback = ({controller}) => { setTimeout(() => controller?.abort(), 3000); };
Expand Down
11 changes: 11 additions & 0 deletions packages/@ama-sdk/create/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,16 @@ module.exports = {
},
'extends': [
'../../../.eslintrc.js'
],
'overrides': [
{
'files': ['package.json'],
'rules': {
'@o3r/json-dependency-versions-harmonize': ['error', {
'ignoredPackages': ['@o3r/build-helpers', 'yarn'],
'alignPeerDependencies': false
}]
}
}
]
};
2 changes: 1 addition & 1 deletion packages/@ama-sdk/create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0",
"yarn": "<2.0.0",
"npm": "*"
"npm": ">=4"
}
}
4 changes: 0 additions & 4 deletions packages/@ama-sdk/showcase-sdk/src/api/pet/pet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export class PetApi implements Api {

/**
* Initialize your interface
*
* @param apiClient Client used to process call to the API
*/
constructor(apiClient: ApiClient) {
Expand Down Expand Up @@ -152,7 +151,6 @@ export class PetApi implements Api {

/**
* Deletes a pet
*
* @param data Data to provide to the API call
* @param metadata Metadata to pass to the API call
*/
Expand Down Expand Up @@ -344,7 +342,6 @@ export class PetApi implements Api {

/**
* Updates a pet in the store with form data
*
* @param data Data to provide to the API call
* @param metadata Metadata to pass to the API call
*/
Expand Down Expand Up @@ -381,7 +378,6 @@ export class PetApi implements Api {

/**
* uploads an image
*
* @param data Data to provide to the API call
* @param metadata Metadata to pass to the API call
*/
Expand Down
1 change: 0 additions & 1 deletion packages/@ama-sdk/showcase-sdk/src/api/store/store-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class StoreApi implements Api {

/**
* Initialize your interface
*
* @param apiClient Client used to process call to the API
*/
constructor(apiClient: ApiClient) {
Expand Down
4 changes: 0 additions & 4 deletions packages/@ama-sdk/showcase-sdk/src/api/user/user-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export class UserApi implements Api {

/**
* Initialize your interface
*
* @param apiClient Client used to process call to the API
*/
constructor(apiClient: ApiClient) {
Expand Down Expand Up @@ -212,7 +211,6 @@ export class UserApi implements Api {

/**
* Get user by user name
*
* @param data Data to provide to the API call
* @param metadata Metadata to pass to the API call
*/
Expand Down Expand Up @@ -249,7 +247,6 @@ export class UserApi implements Api {

/**
* Logs user into the system
*
* @param data Data to provide to the API call
* @param metadata Metadata to pass to the API call
*/
Expand Down Expand Up @@ -286,7 +283,6 @@ export class UserApi implements Api {

/**
* Logs out current logged in user session
*
* @param data Data to provide to the API call
* @param metadata Metadata to pass to the API call
*/
Expand Down
1 change: 0 additions & 1 deletion packages/@ama-sdk/showcase-sdk/src/spec/api-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const myApi: Api = {

/**
* Retrieve mocked SDK Apis
*
* @param config configuration of the Api Client
*/
export function getMockedApi(config?: string | BaseApiFetchClientConstructor | ApiClient): Api {
Expand Down
26 changes: 13 additions & 13 deletions packages/@ama-sdk/showcase-sdk/src/spec/operation-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ import {PathObject} from '@ama-sdk/core';

/* eslint-disable max-len */
export const OPERATION_ADAPTER: PathObject[] = [{
path: '/pet',regexp: new RegExp('^/pet(?:/(?=$))?$'),operations: [{'method':'post','operationId':'addPet'},{'method':'put','operationId':'updatePet'}]
path: '/pet',regexp: new RegExp('^/pet(?:/(?=$))?$'),operations: [{'method': 'post','operationId': 'addPet'},{'method': 'put','operationId': 'updatePet'}]
},{
path: '/pet/findByStatus',regexp: new RegExp('^/pet/findByStatus(?:/(?=$))?$'),operations: [{'method':'get','operationId':'findPetsByStatus'}]
path: '/pet/findByStatus',regexp: new RegExp('^/pet/findByStatus(?:/(?=$))?$'),operations: [{'method': 'get','operationId': 'findPetsByStatus'}]
},{
path: '/pet/findByTags',regexp: new RegExp('^/pet/findByTags(?:/(?=$))?$'),operations: [{'method':'get','operationId':'findPetsByTags'}]
path: '/pet/findByTags',regexp: new RegExp('^/pet/findByTags(?:/(?=$))?$'),operations: [{'method': 'get','operationId': 'findPetsByTags'}]
},{
path: '/pet/{petId}',regexp: new RegExp('^/pet/((?:[^/]+?))(?:/(?=$))?$'),operations: [{'method':'get','operationId':'getPetById'},{'method':'post','operationId':'updatePetWithForm'},{'method':'delete','operationId':'deletePet'}]
path: '/pet/{petId}',regexp: new RegExp('^/pet/((?:[^/]+?))(?:/(?=$))?$'),operations: [{'method': 'get','operationId': 'getPetById'},{'method': 'post','operationId': 'updatePetWithForm'},{'method': 'delete','operationId': 'deletePet'}]
},{
path: '/pet/{petId}/uploadImage',regexp: new RegExp('^/pet/((?:[^/]+?))/uploadImage(?:/(?=$))?$'),operations: [{'method':'post','operationId':'uploadFile'}]
path: '/pet/{petId}/uploadImage',regexp: new RegExp('^/pet/((?:[^/]+?))/uploadImage(?:/(?=$))?$'),operations: [{'method': 'post','operationId': 'uploadFile'}]
},{
path: '/store/inventory',regexp: new RegExp('^/store/inventory(?:/(?=$))?$'),operations: [{'method':'get','operationId':'getInventory'}]
path: '/store/inventory',regexp: new RegExp('^/store/inventory(?:/(?=$))?$'),operations: [{'method': 'get','operationId': 'getInventory'}]
},{
path: '/store/order',regexp: new RegExp('^/store/order(?:/(?=$))?$'),operations: [{'method':'post','operationId':'placeOrder'}]
path: '/store/order',regexp: new RegExp('^/store/order(?:/(?=$))?$'),operations: [{'method': 'post','operationId': 'placeOrder'}]
},{
path: '/store/order/{orderId}',regexp: new RegExp('^/store/order/((?:[^/]+?))(?:/(?=$))?$'),operations: [{'method':'get','operationId':'getOrderById'},{'method':'delete','operationId':'deleteOrder'}]
path: '/store/order/{orderId}',regexp: new RegExp('^/store/order/((?:[^/]+?))(?:/(?=$))?$'),operations: [{'method': 'get','operationId': 'getOrderById'},{'method': 'delete','operationId': 'deleteOrder'}]
},{
path: '/user',regexp: new RegExp('^/user(?:/(?=$))?$'),operations: [{'method':'post','operationId':'createUser'}]
path: '/user',regexp: new RegExp('^/user(?:/(?=$))?$'),operations: [{'method': 'post','operationId': 'createUser'}]
},{
path: '/user/createWithList',regexp: new RegExp('^/user/createWithList(?:/(?=$))?$'),operations: [{'method':'post','operationId':'createUsersWithListInput'}]
path: '/user/createWithList',regexp: new RegExp('^/user/createWithList(?:/(?=$))?$'),operations: [{'method': 'post','operationId': 'createUsersWithListInput'}]
},{
path: '/user/login',regexp: new RegExp('^/user/login(?:/(?=$))?$'),operations: [{'method':'get','operationId':'loginUser'}]
path: '/user/login',regexp: new RegExp('^/user/login(?:/(?=$))?$'),operations: [{'method': 'get','operationId': 'loginUser'}]
},{
path: '/user/logout',regexp: new RegExp('^/user/logout(?:/(?=$))?$'),operations: [{'method':'get','operationId':'logoutUser'}]
path: '/user/logout',regexp: new RegExp('^/user/logout(?:/(?=$))?$'),operations: [{'method': 'get','operationId': 'logoutUser'}]
},{
path: '/user/{username}',regexp: new RegExp('^/user/((?:[^/]+?))(?:/(?=$))?$'),operations: [{'method':'get','operationId':'getUserByName'},{'method':'put','operationId':'updateUser'},{'method':'delete','operationId':'deleteUser'}]
path: '/user/{username}',regexp: new RegExp('^/user/((?:[^/]+?))(?:/(?=$))?$'),operations: [{'method': 'get','operationId': 'getUserByName'},{'method': 'put','operationId': 'updateUser'},{'method': 'delete','operationId': 'deleteUser'}]
}];
/* eslint-enable max-len */
2 changes: 1 addition & 1 deletion packages/@ama-terasu/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0",
"vscode": "^1.22.0"
"vscode": "^1.67.0"
},
"preferUnplugged": true
}
2 changes: 1 addition & 1 deletion packages/@ama-terasu/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
},
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0",
"vscode": "^1.22.0"
"vscode": "^1.67.0"
}
}
2 changes: 1 addition & 1 deletion packages/@ama-terasu/schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"schematics": "./dist/collection.json",
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0",
"vscode": "^1.22.0"
"vscode": "^1.67.0"
},
"dependencies": {
"@angular-devkit/architect": "~0.1800.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@o3r/amaterasu/amaterasu-api-spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
},
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0",
"vscode": "^1.22.0"
"vscode": "^1.67.0"
}
}
2 changes: 1 addition & 1 deletion packages/@o3r/amaterasu/amaterasu-otter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
},
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0",
"vscode": "^1.22.0"
"vscode": "^1.67.0"
}
}
2 changes: 1 addition & 1 deletion packages/@o3r/amaterasu/amaterasu-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
},
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0",
"vscode": "^1.22.0"
"vscode": "^1.67.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Directive, ElementRef, Renderer2} from '@angular/core';
import {Directive, ElementRef, OnDestroy, Renderer2} from '@angular/core';
import {Subscription} from 'rxjs';

import {
Expand All @@ -11,7 +11,7 @@ import {
import {EventTrackService} from '../../services/event-track';

@Directive()
export abstract class BaseTrackEvents {
export abstract class BaseTrackEvents implements OnDestroy {
/**
* Custom object to be stored when the click event is captured
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AfterViewChecked,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Expand Down Expand Up @@ -32,7 +33,7 @@ import {PlaceholderLoadingStatus, PlaceholderLoadingStatusMessage} from './place
'[class.debug]': `mode() === 'debug'`
}
})
export class PlaceholderComponent implements OnInit, OnDestroy {
export class PlaceholderComponent implements OnInit, OnDestroy, AfterViewChecked {

private readonly subscription = new Subscription();

Expand Down
11 changes: 11 additions & 0 deletions packages/@o3r/create/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,16 @@ module.exports = {
},
'extends': [
'../../../.eslintrc.js'
],
'overrides': [
{
'files': ['package.json'],
'rules': {
'@o3r/json-dependency-versions-harmonize': ['error', {
'ignoredPackages': ['@o3r/build-helpers', 'yarn'],
'alignPeerDependencies': false
}]
}
}
]
};
2 changes: 1 addition & 1 deletion packages/@o3r/create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0",
"yarn": "<2.0.0",
"npm": "*"
"npm": ">=4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const packageJsonWorkspace = {
],
dependencies: {
myDep: '^2.0.0'
},
engines: {
node: '^21.0.0'
}
};

Expand Down Expand Up @@ -62,7 +65,9 @@ ruleTester.run('json-dependency-versions-harmonize', jsonDependencyVersionsHarmo
{ code: JSON.stringify({ resolutions: { 'test/sub/myDep': '1.0.0' } }), filename: packageToLint, options: [{ alignResolutions: false }] },
// eslint-disable-next-line @typescript-eslint/naming-convention
{ code: JSON.stringify({ overrides: { test: { myDep: '1.0.0' } } }), filename: packageToLint, options: [{ alignResolutions: false }] },
{ code: JSON.stringify({ overrides: { myDep: '1.0.0' } }), filename: packageToLint, options: [{ alignResolutions: false }] }
{ code: JSON.stringify({ overrides: { myDep: '1.0.0' } }), filename: packageToLint, options: [{ alignResolutions: false }] },
{ code: JSON.stringify({ engines: { node: '<20' } }), filename: packageToLint, options: [{ alignEngines: false }] },
{ code: JSON.stringify({ engines: { node: '>21.1' } }), filename: packageToLint, options: [{ alignEngines: true }] }
],
invalid: [
{
Expand Down Expand Up @@ -189,6 +194,24 @@ ruleTester.run('json-dependency-versions-harmonize', jsonDependencyVersionsHarmo
}
}
]
},
{
filename: packageToLint,
// eslint-disable-next-line @typescript-eslint/naming-convention
output: JSON.stringify({ engines: { node: '^21.0.0' } }),
// eslint-disable-next-line @typescript-eslint/naming-convention
code: JSON.stringify({ engines: { node: '<20' } }),
options: [{ alignEngines: true }],
errors: [
{
messageId: 'error',
data: {
depName: 'node',
packageJsonFile: path.join(fakeFolder, 'local', 'package.json'),
version: '^21.0.0'
}
}
]
}
]
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ interface Options {
alignPeerDependencies?: boolean;
/** Align the resolutions/overrides dependency rules with the latest determined range */
alignResolutions?: boolean;
/** Align the Engines versions */
alignEngines?: boolean;
}

const defaultOptions: [Required<Options>] = [{
ignoredDependencies: [],
dependencyTypes: ['optionalDependencies', 'dependencies', 'devDependencies', 'peerDependencies', 'generatorDependencies'],
alignPeerDependencies: false,
alignResolutions: true,
alignEngines: false,
ignoredPackages: []
}];

const resolutionsFields = ['resolutions', 'overrides'];
const enginesField = 'engines';

export default createRule<[Options, ...any], 'versionUpdate' | 'error'>({
name: 'json-dependency-versions-harmonize',
meta: {
Expand Down Expand Up @@ -71,6 +77,10 @@ export default createRule<[Options, ...any], 'versionUpdate' | 'error'>({
alignResolutions: {
type: 'boolean',
description: 'Align the resolutions dependencies with the latest determined range.'
},
alignEngines: {
type: 'boolean',
description: 'Align the engines constraints with the latest determined range.'
}
},
additionalProperties: false
Expand All @@ -84,13 +94,13 @@ export default createRule<[Options, ...any], 'versionUpdate' | 'error'>({
},
defaultOptions,
create: (context, [options]: Readonly<[Options, ...any]>) => {
const resolutionsFields = ['resolutions', 'overrides'];
const parserServices = getJsoncParserServices(context);
const dirname = path.dirname(context.getFilename());
const dirname = path.dirname(context.filename);
const workspace = findWorkspacePackageJsons(dirname);
const bestRanges = workspace && getBestRanges(options.dependencyTypes!, workspace.packages.filter(({ content }) => !content.name || !options.ignoredPackages!.includes(content.name)));
const dependencyTypesWithInterest = [...options.dependencyTypes!, ...(options.alignEngines ? [enginesField] : [])];
const bestRanges = workspace && getBestRanges(dependencyTypesWithInterest, workspace.packages.filter(({ content }) => !content.name || !options.ignoredPackages!.includes(content.name)));
const ignoredDependencies = options.ignoredDependencies!.map((dep) => new RegExp(dep.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*')));
const dependencyTypes = [...options.dependencyTypes!, ...(options.alignResolutions ? resolutionsFields : [])];
const dependencyTypes = [...dependencyTypesWithInterest, ...(options.alignResolutions ? resolutionsFields : [])];

if (parserServices.isJSON) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectorRef, Directive, ElementRef, Inject, Input } from '@angular/core';
import { ChangeDetectorRef, Directive, ElementRef, Inject, Input, OnDestroy } from '@angular/core';
import { TranslateDirective, TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { LocalizationConfiguration } from '../core';
Expand All @@ -10,7 +10,7 @@ import { LOCALIZATION_CONFIGURATION_TOKEN } from './localization.token';
@Directive({
selector: '[translate],[ngx-translate]'
})
export class LocalizationTranslateDirective extends TranslateDirective {
export class LocalizationTranslateDirective extends TranslateDirective implements OnDestroy {
/**
* Internal subscription to the LocalizationService showKeys mode changes
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectorRef, Inject, Pipe, PipeTransform } from '@angular/core';
import { ChangeDetectorRef, Inject, OnDestroy, Pipe, PipeTransform } from '@angular/core';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { LocalizationConfiguration } from '../core';
Expand All @@ -9,7 +9,7 @@ import { LOCALIZATION_CONFIGURATION_TOKEN } from './localization.token';
* TranslatePipe class adding debug functionality
*/
@Pipe({name: 'o3rTranslate', pure: false})
export class O3rLocalizationTranslatePipe extends TranslatePipe implements PipeTransform {
export class O3rLocalizationTranslatePipe extends TranslatePipe implements PipeTransform, OnDestroy {
/**
* Internal subscription to the LocalizationService showKeys mode changes
*/
Expand Down
Loading

0 comments on commit 43f6e92

Please sign in to comment.