Skip to content

Commit

Permalink
Merge pull request #52 from solarflare045/feat/eslint-flat-config-format
Browse files Browse the repository at this point in the history
refactor: refactoring to use new eslint file format
  • Loading branch information
solarflare045 authored Nov 15, 2024
2 parents ad763f6 + 907ff11 commit 7ff7a34
Show file tree
Hide file tree
Showing 39 changed files with 9,447 additions and 6,906 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: wagoid/commitlint-github-action@v4
with:
configFile: .commitlintrc.yml
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

Expand Down
18 changes: 12 additions & 6 deletions .github/workflows/test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm ci

- name: Test base configuration
run: npm run test
- name: Build
run: npm run build

- name: Lint Self
run: npm run lint

- name: Test mild configuration
run: npm run test:mild
- name: Install Example Project dependencies
run : (cd example-project && npm ci)

- name: Lint Example Project
run: npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
dist/
1 change: 0 additions & 1 deletion .prettierrc

This file was deleted.

46 changes: 16 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@

You can install **`eslint-config-intolerable-style-guide`** using npm via
```
npm install -D eslint-config-intolerable-style-guide eslint
npm install -D eslint-config-intolerable-style-guide eslint@9
```
The config will install all the plugins and whatnot, but this relies on eslint's plugin system finding them in the top of the node_modules kinda by chance. They _should_ be peer dependancies, but I reckon it'll be fine like this. Worst case scenario: you just install the plugins needed yourself.

## Configuration

If you look in the `example-project` folder, it will have the files you need.
They are all optional except for `.eslintrc.yml`. At a minimum, that will need to be:
```yml
extends:
- intolerable-style-guide
parserOptions:
project: ./tsconfig.json
root: true
You can configure ESLint to use the Intolerable Style Guide by adding the following `eslint.config.js` to your project:
```javascript
const { ISG } = require('eslint-config-intolerable-style-guide');

module.exports = [
...ISG,

{
languageOptions: {
parserOptions: {
project: './tsconfig.json',
},
},
},
];
```
The `.eslintignore` file is a gitignore style file to tell the linter what folders not to look at.
The `.prettierrc` and `.prettierignore` files will tell your IDE how to do formatting if you use the prettier plugin for it. If you just want eslint to fix those, you can leave it out.

It is also recommended to manually add a linting script to your `package.json`, which should look like this:

Expand All @@ -50,21 +54,3 @@ You could also consider running [lint-staged](https://github.com/okonet/lint-sta
## Querks

None. It is perfect.

## How to maintain

### Files
The main ruleset is maintained in the [`index.js`](index.js) file. Most rules are commented with their justification for existence, and why decisions have been made.
There is also a [`jest.js`](jest.js) for including in projects that have jest.
And last there is the [`prettier.json`](prettier.json) file that includes the prettier config. These are the big 3 files that are used when importing this config. If you add any, be sure to put them in the `package.json` `files` setting, as this repo is published with a whitelist and you new file will not be included in the publish without it.
This repository does not get transpiled at all, so ensure the code you write is compatible with the versions of node you want to run on.

### Commits
This repository follows the [Conventional Commits](https://conventionalcommits.org) pattern for commit messages.

### Release
When it comes time for a release you should be able to find a pull request on the github repo that is offering to bump the version and update the changelog. This will also tag the github repo.
If you don't want to use this bot (or it broke or something), then you can fall back to running the `npm run release` command and it will do the same thing for you.

### Publishing
To publish to NPM you just need to push a tag to github and it will automatically run the [workflow](.github/workflows/publish.yml) to do this. You could also just publish locally.
14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { ISG } = require('./dist');

// This file is used for internal testing only.
module.exports = [
...ISG,

{
languageOptions: {
parserOptions: {
project: './tsconfig.json',
},
},
},
];
3 changes: 0 additions & 3 deletions example-project/.eslintignore

This file was deleted.

12 changes: 0 additions & 12 deletions example-project/.eslintrc.yml

This file was deleted.

3 changes: 0 additions & 3 deletions example-project/.prettierignore

This file was deleted.

1 change: 0 additions & 1 deletion example-project/.prettierrc

This file was deleted.

14 changes: 14 additions & 0 deletions example-project/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { ISG } = require('eslint-config-intolerable-style-guide');

// This file is used for internal testing only.
module.exports = [
...ISG,

{
languageOptions: {
parserOptions: {
project: './tsconfig.json',
},
},
},
];
55 changes: 55 additions & 0 deletions example-project/package-lock.json

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

14 changes: 14 additions & 0 deletions example-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "example-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"lint": "eslint -c ./eslint.config.js ./src/good-file.ts"
},
"dependencies": {
"eslint-config-intolerable-style-guide": ".."
},
"author": "",
"license": "ISC"
}
6 changes: 6 additions & 0 deletions test/example.ts → example-project/src/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ if (c) {
console.log('BLARG');
}
}

async function main() {

}

main();
File renamed without changes.
103 changes: 103 additions & 0 deletions example-project/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */

/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */

/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */

/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
16 changes: 0 additions & 16 deletions helpers/iif.js

This file was deleted.

Loading

0 comments on commit 7ff7a34

Please sign in to comment.