Skip to content

Commit

Permalink
refactor: move eslint-rules to eslint-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Sep 13, 2024
1 parent ffbdade commit 5146fd4
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This repository contains several helpful packages for NestJS that I have develop
| [AMQP-Transport](./packages/amqp-transport/README.md) | A NestJS microservice adapter around [AMQPlib] supporting exchanges. | [![npm](https://img.shields.io/npm/v/@getlarge/nestjs-tools-amqp-transport.svg?style=flat)](https://npmjs.org/package/@getlarge/nestjs-tools-amqp-transport) |
| [Async-Local-Storage](./packages/async-local-storage/README.md) | A NestJS module to track context with [AsyncLocalStorage]. | [![npm](https://img.shields.io/npm/v/@getlarge/nestjs-tools-async-local-storage?style=flat)](https://npmjs.org/package/@getlarge/nestjs-tools-async-local-storage) |
| [Cluster](./packages/cluster/README.md) | A class to manage workers' lifecycle in a (Node.js) [cluster]. | [![npm](https://img.shields.io/npm/v/@getlarge/nestjs-tools-cluster?style=flat)](https://npmjs.org/package/@getlarge/nestjs-tools-cluster) |
| [ESLint-Rules](./packages/eslint-rules/README.md) | A set of ESLint rules for NestJS applications. | [![npm](https://img.shields.io/npm/v/@getlarge/nestjs-tools-eslint-rules?style=flat)](https://npmjs.org/package/@getlarge/nestjs-tools-eslint-rules) |
| [ESLint-Plugin](./packages/eslint-plugin-/README.md) | A set of ESLint rules for NestJS applications. | [![npm](https://img.shields.io/npm/v/@getlarge/eslint-plugin-nestjs-tools?style=flat)](https://npmjs.org/package/@getlarge/eslint-plugin-nestjs-tools) |
| [File-Storage](./packages/file-storage/README.md) | A NestJS module supporting [FS], [S3] and [GCP] strategies. | [![npm](https://img.shields.io/npm/v/@getlarge/nestjs-tools-file-storage?style=flat)](https://npmjs.org/package/@getlarge/nestjs-tools-file-storage) |
| [Lock](./packages/lock/README.md) | A NestJS module to provide a distributed lock for your application. | [![npm](https://img.shields.io/npm/v/@getlarge/nestjs-tools-lock?style=flat)](https://npmjs.org/package/@getlarge/nestjs-tools-lock) |
| [Fastify-Upload](./packages/fastify-upload/README.md) | A NestJS module to provide file upload support for Fastify. | [![npm](https://img.shields.io/npm/v/@getlarge/nestjs-tools-fastify-upload?style=flat)](https://npmjs.org/package/@getlarge/nestjs-tools-fastify-upload) |
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# eslint-rules
# eslint-plugin

[![npm][npm-image]][npm-url]

[npm-image]: https://img.shields.io/npm/v/@getlarge/nestjs-tools-eslint-rules.svg?style=flat
[npm-url]: https://npmjs.org/package/@getlarge/nestjs-tools-eslint-rules
[npm-image]: https://img.shields.io/npm/v/@getlarge/eslint-plugin-nestjs-tools.svg?style=flat
[npm-url]: https://npmjs.org/package/@getlarge/eslint-plugin-nestjs-tools

This set of ESLint rules is provided to enforce a consistent patterns and practices across all NestJS projects.

## Installation

```bash
npm install --save @getlarge/nestjs-tools-eslint-rules
npm install --save @getlarge/eslint-plugin-nestjs-tools
```

## Usage
Expand All @@ -23,7 +23,7 @@ The purpose of this rule is to ensure you return class instances instead of plai
```json
{
"rules": {
"@getlarge/nestjs-tools-eslint-rules/return-class-instance": "error"
"@getlarge/eslint-plugin-nestjs-tools/return-class-instance": "error"
}
}
```
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable */
export default {
displayName: 'eslint-rules',
displayName: 'eslint-plugin',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/eslint-rules',
coverageDirectory: '../../coverage/packages/eslint-plugin',
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "@getlarge/nestjs-tools-eslint-rules",
"name": "@getlarge/eslint-plugin-nestjs-tools",
"version": "0.1.0",
"description": "ESLint rules for NestJS applications",
"keywords": [
"eslint",
"eslint-plugin",
"eslintplugin",
"nestjs",
"rules",
"typescript",
Expand All @@ -12,13 +14,16 @@
],
"license": "Apache-2.0",
"author": "Edouard Maleix <[email protected]>",
"homepage": "https://github.com/getlarge/nestjs-tools/tree/main/packages/eslint-rules",
"homepage": "https://github.com/getlarge/nestjs-tools/tree/main/packages/eslint-plugin",
"publishConfig": {
"access": "public"
},
"dependencies": {},
"dependencies": {
"@typescript-eslint/utils": "8.5.0"
},
"peerDependencies": {
"eslint": "7 || 8 || 9"
"@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0",
"eslint": "^8.57.0 || ^9.0.0"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
21 changes: 21 additions & 0 deletions packages/eslint-plugin/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "eslint-plugin-nestjs-tools",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/eslint-plugin/src",
"projectType": "library",
"tags": [],
"// targets": "to see all targets run: nx show project eslint-plugin-nestjs-tools --web",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/eslint-plugin",
"tsConfig": "packages/eslint-plugin/tsconfig.lib.json",
"packageJson": "packages/eslint-plugin/package.json",
"main": "packages/eslint-plugin/src/index.ts",
"assets": ["packages/eslint-plugin/*.md"]
}
}
}
}
18 changes: 18 additions & 0 deletions packages/eslint-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Linter } from '@typescript-eslint/utils/dist/ts-eslint';

import { rule as returnClassInstance, RULE_NAME as returnClassInstanceName } from './lib/return-class-instance';

// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { name, version } = require('../package.json') as {
name: string;
version: string;
};

export default {
meta: {
name,
version,
},
rules: { [returnClassInstanceName]: returnClassInstance },
} satisfies Linter.Plugin;
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
/* eslint-disable max-lines-per-function */
/**
* This file sets you up with structure needed for an ESLint rule.
*
* It leverages utilities from @typescript-eslint to allow TypeScript to
* provide autocompletions etc for the configuration.
*
* Your rule's custom logic will live within the create() method below
* and you can learn more about writing ESLint rules on the official guide:
*
* https://eslint.org/docs/developer-guide/working-with-rules
*
* You can also view many examples of existing rules here:
*
* https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/src/rules
*/

import { ESLintUtils } from '@typescript-eslint/utils';

// NOTE: The rule will be available in ESLint configs as "@nx/workspace/return-class-instance"
export const RULE_NAME = '@getlarge/nestjs-tools-eslint-rules/return-class-instance';
export const RULE_NAME = '@getlarge/eslint-plugin-nestjs-tools/return-class-instance';

const getTypeNameFromReturnType = (rawReturnType: string) => {
return rawReturnType.replaceAll(/Promise<([^<>]*)>/g, '$1').replace(': ', '');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 0 additions & 21 deletions packages/eslint-rules/project.json

This file was deleted.

5 changes: 0 additions & 5 deletions packages/eslint-rules/src/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@getlarge/nestjs-tools-amqp-transport": ["packages/amqp-transport/src/index.ts"],
"@getlarge/nestjs-tools-async-local-storage": ["packages/async-local-storage/src/index.ts"],
"@getlarge/nestjs-tools-cluster": ["packages/cluster/src/index.ts"],
"@getlarge/nestjs-tools-eslint-rules": ["packages/eslint-rules/src/index.ts"],
"@getlarge/eslint-plugin-nestjs-tools": ["packages/eslint-plugin/src/index.ts"],
"@getlarge/nestjs-tools-fastify-upload": ["packages/fastify-upload/src/index.ts"],
"@getlarge/nestjs-tools-file-storage": ["packages/file-storage/src/index.ts"],
"@getlarge/nestjs-tools-lock": ["packages/lock/src/index.ts"],
Expand Down

0 comments on commit 5146fd4

Please sign in to comment.