Skip to content

Commit

Permalink
fix(eslint-config-ng): Extract eslint config to a new project. Allows…
Browse files Browse the repository at this point in the history
… using it in a JSON config file
  • Loading branch information
ersimont committed May 23, 2021
1 parent 23a9784 commit cb84b1b
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./projects/ng-dev/src/eslint-config.json",
"extends": "./projects/eslint-config-ng",
"overrides": [
{
"files": ["*.ts"],
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ All notable changes to this project will be documented in this file. See [standa

### ⚠ BREAKING CHANGES

- **ng-dev:** ESLint is no longer installed automatically with `ng-dev`. The old TSLint and ESLint configs are deprecated, but you can continue to use them for now if you install the old dependencies via your own `package.json`. The were: `"@typescript-eslint/eslint-plugin": "^4.8.0"`, "@typescript-eslint/parser": "^4.6.0"`, and `"eslint": "^7.14.0"`. Consult the README for instructions to set up the new ESLint config at your convenience; the old configs will be removed from this library in a future version.
- **ng-dev:** Linting config is now provided by [`@s-libs/eslint-config-ng`](https://github.com/simontonsoftware/s-libs/tree/master/projects/eslint-config-ng). The old TSLint and ESLint configs are still available in `ng-dev`, but are deprecated. ESLint is no longer installed automatically with `ng-dev`, so to continue using its deprecated config you'll need to install the old dependencies via your own `package.json`. They were: `"@typescript-eslint/eslint-plugin": "^4.8.0"`, `"@typescript-eslint/parser": "^4.6.0"`, and `"eslint": "^7.14.0"`. Consult the [README for eslint-config-ng](https://github.com/simontonsoftware/s-libs/tree/master/projects/eslint-config-ng) to to switch to the new configs. The old ones will be removed from this library in a future version.
- all 3rd party dependencies require bumped version numbers
- **ng-core:** `AngularContextNext` and `ComponentContextNext` are renamed to replace their old, deprecated versions. If you are still using the old ones, switch to the "Next" versions and get your tests passing before upgrading to `@s-libs` version 12. Once you are on the "Next" versions, this upgrade only requires removing "Next" from the ends of the names.
- **ng-core:** `AngularContextNext` and `ComponentContextNext` are renamed to replace their old, deprecated versions. If you are still using the old ones, switch to the "Next" versions and get your tests passing before upgrading to `@s-libs` version 12. Once you are on the "Next" versions, this upgrade only requires removing "Next" from the ends of their names.

### Features

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This is a collection of libraries from Simonton Software, written in TypeScript
- [`ng-core`](https://github.com/simontonsoftware/s-libs/tree/master/projects/ng-core): Miscellaneous utilities for Angular
- [`ng-app-state`](https://github.com/simontonsoftware/s-libs/tree/master/projects/ng-app-state): Painlessly integrate `app-state` into template-driven Angular forms
- [`ng-dev`](https://github.com/simontonsoftware/s-libs/tree/master/projects/ng-dev): Miscellaneous utilities to use while developing Angular apps
- [`eslint-config-ng`](https://github.com/simontonsoftware/s-libs/tree/master/projects/eslint-config-dev):

## Upgrading from the loose packages

Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
- coveralls
- help may be here, to combine multiple coverage runs into one report: https://github.com/angular/angular-cli/issues/11268
- Watch for when typedoc can support that "lib" mode that would eliminate the need for @hidden
- Remove upgrade notes from the old standalone packages
32 changes: 32 additions & 0 deletions projects/eslint-config-ng/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
This library provides some default config you can use for ESLint in an Angular project. It gives you all the recommended, community-standard rules from ESLint,
@typescript-eslint, and @angular-eslint/recommended, plus these additions and changes:

- code complexity rules to keep your functions and files focused and readable
- relaxed rules around `ban-types` that Simonton Software has found unuseful

# Installation

1. First install [Angular ESLint](https://github.com/angular-eslint/angular-eslint) following their instructions for your situation. Make sure it is working with their minimal config.
1. `yarn add -D @s-libs/eslint-config-ng`
1. Change `.eslintrc.json` in your root directory to this, and make adjustments to suit your needs:

```json
{
"extends": "@s-libs/eslint-config-ng",
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{ "type": "attribute", "prefix": "app", "style": "camelCase" }
],
"@angular-eslint/component-selector": [
"error",
{ "type": "element", "prefix": "app", "style": "kebab-case" }
]
}
}
]
}
```
File renamed without changes.
19 changes: 19 additions & 0 deletions projects/eslint-config-ng/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@s-libs/eslint-config-ng",
"version": "12.0.0-next.0",
"author": "Simonton Software",
"license": "MIT",
"homepage": "https://github.com/simontonsoftware/s-libs/tree/master/projects/eslint-config-ng",
"repository": {
"type": "git",
"url": "https://github.com/simontonsoftware/s-libs.git",
"directory": "projects/eslint-config-ng"
},
"peerDependencies": {
"@angular-eslint/eslint-plugin": "^12.0.0",
"@angular-eslint/eslint-plugin-template": "^12.0.0",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "4.23.0",
"eslint": "^7.26.0"
}
}
17 changes: 2 additions & 15 deletions projects/ng-dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@ To quickly see what is available, see the [api documentation](https://simontonso
## Installation

```
yarn add -D @s-libs/ng-dev @s-libs/ng-core @s-libs/rxjs-core @s-libs/js-core @s-libs/micro-dash @angular/cdk
yarn add @s-libs/ng-core @s-libs/rxjs-core @s-libs/js-core @s-libs/micro-dash @angular/cdk
yarn add -D @s-libs/ng-dev
```

## ESLint Config

This library comes with some default config you can use for ESLint. It to use it, first install [Angular ESLint](https://github.com/angular-eslint/angular-eslint) following their instructions for your situation. Make sure it is working with their minimal config, then change `.eslintrc.json` in your root directory to this:

```json
{ "extends": "@s-libs/ng-dev/eslint-config.json" }
```

This will give you all the recommended, community-standard rules from ESLint, "eslint:recommended",
@typescript-eslint, and @angular-eslint/recommended, plus these additions and changes:

- code complexity rules to keep your functions and files focused and readable
- relaxed rules around `ban-types` that Simonton Software has found unuseful
4 changes: 2 additions & 2 deletions scripts/build-libs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { libraries, runCommand } from './shared';
import { buildableLibraries, runCommand } from './shared';

for (const project of libraries) {
for (const project of buildableLibraries) {
runCommand(`yarn build --configuration production ${project}`);
}
27 changes: 27 additions & 0 deletions scripts/copy-eslint-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { copyFileSync, mkdirSync, readdirSync, rmdirSync } from 'fs';
import { join } from 'path';

export function copyEslintConfig() {
const targetFolder = 'dist/eslint-config-ng';
rmdirSync(targetFolder, { recursive: true });
mkdirSync(targetFolder);

const srcFolder = 'projects/eslint-config-ng';
for (const file of readdirSync(srcFolder)) {
copyFileSync(join(srcFolder, file), join(targetFolder, file));
}

// deprecated config
copyFileSync(
'projects/ng-dev/deprecated-config/.eslintrc.js',
'dist/ng-dev/.eslintrc.js',
);
copyFileSync(
'projects/ng-dev/deprecated-config/tslint.angularcli.json',
'dist/ng-dev/tslint.angularcli.json',
);
copyFileSync(
'projects/ng-dev/deprecated-config/tslint.json',
'dist/ng-dev/tslint.json',
);
}
3 changes: 0 additions & 3 deletions scripts/copy-extra-dist-files.ts

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/docs-libs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { libraries, runCommand } from './shared';
import { buildableLibraries, runCommand } from './shared';

let projects = process.argv.slice(2);
if (projects.length === 0) {
projects = libraries;
projects = buildableLibraries;
}

for (const project of projects) {
Expand Down
3 changes: 2 additions & 1 deletion scripts/publish-libs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { copyEslintConfig, getInput, libraries, runCommand } from './shared';
import { copyEslintConfig } from './copy-eslint-config';
import { getInput, libraries, runCommand } from './shared';

async function run(): Promise<void> {
copyEslintConfig();
Expand Down
24 changes: 3 additions & 21 deletions scripts/shared.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { execSync } from 'child_process';
import { copyFileSync } from 'fs';
import { createInterface } from 'readline';

// in dependency order
export const libraries = [
export const buildableLibraries = [
'micro-dash',
'js-core',
'rxjs-core',
Expand All @@ -13,6 +12,8 @@ export const libraries = [
'ng-dev',
];

export const libraries = [...buildableLibraries, 'eslint-config-ng'];

export function runCommand(command: string): void {
execSync(command, { stdio: 'inherit' });
}
Expand All @@ -26,22 +27,3 @@ export function getInput(text: string): Promise<string> {
});
});
}

export function copyEslintConfig() {
copyFileSync(
'projects/ng-dev/src/eslint-config.json',
'dist/ng-dev/eslint-config.json',
);
copyFileSync(
'projects/ng-dev/deprecated-config/.eslintrc.js',
'dist/ng-dev/.eslintrc.js',
);
copyFileSync(
'projects/ng-dev/deprecated-config/tslint.angularcli.json',
'dist/ng-dev/tslint.angularcli.json',
);
copyFileSync(
'projects/ng-dev/deprecated-config/tslint.json',
'dist/ng-dev/tslint.json',
);
}

0 comments on commit cb84b1b

Please sign in to comment.