Skip to content

Commit

Permalink
make esm rules optional (#1)
Browse files Browse the repository at this point in the history
* make esm rules optional

- adjust example
- fix rules

* jsdoc
  • Loading branch information
foxriver76 authored Sep 6, 2024
1 parent 0854e5f commit 07cd5ff
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@ npm i @iobroker/eslint-config --save-dev
Just extend this project in your lint config in your `eslint.config.mjs`.

```js
import config from '@iobroker/eslint-config'
import config from '@iobroker/eslint-config';

export default [...config]
export default [...config];
```

And create a `prettier.config.js` with the following content:
And create a `prettier.config.mjs` with the following content:

```js
module.exports = require('@iobroker/eslint-config/prettier');
import prettierConfig from '@iobroker/eslint-config/prettier.config.mjs';

export default prettierConfig;
```

Optionally, if you are using ESM modules, there is an additional config.
Your `eslint.config.mjs` would then look like this:

```js
import config, { esmConfig } from '@iobroker/eslint-config';

export default [...config, ...esmConfig];
```

## Changelog
Expand Down
37 changes: 28 additions & 9 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import eslint from "@eslint/js";
import jsdoc from "eslint-plugin-jsdoc";
import tseslint from "typescript-eslint";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import globals from 'globals'

/**
* Rules for all JSDOC plugin usages
Expand All @@ -27,7 +28,7 @@ const unicornRules = {
};

/**
* General rules
* General rules, applied to all files
*/
const generalRules = {
"curly": ["error"],
Expand All @@ -37,12 +38,15 @@ const generalRules = {
"error",
"as-needed"
],
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unused-expressions": "off",
}

/** General TypeScript rules */
const tsRules = {
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-use-before-define": [
"error",
{
Expand Down Expand Up @@ -100,8 +104,10 @@ const tsRules = {
"allowExpressions": true
}
],
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-for-in-array": "warn",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-call": "off",
Expand Down Expand Up @@ -133,21 +139,34 @@ export default tseslint.config(
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: globals.node,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname
tsconfigRootDir: import.meta.dirname,
}
}
},
{
plugins: { unicorn: eslintPluginUnicorn },
rules: unicornRules
},
{
plugins: { jsdoc },
rules: jsdocRules
},
{
rules: {...generalRules, ...tsRules }
rules: generalRules
},
{
files: ['**/*.ts', '**/*.tsx'],
rules: tsRules
},
);
{
files: ['**/*.js'],
...tseslint.configs.disableTypeChecked,
},
);

/**
* Additional rules for ESM modules
*/
export const esmConfig = [{
plugins: { unicorn: eslintPluginUnicorn },
rules: unicornRules
}]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"files": [
"eslint.config.mjs",
"prettier.js",
"prettier.config.mjs",
"README.md"
],
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion prettier.js → prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
printWidth: 120,
semi: true,
tabWidth: 4,
Expand Down

0 comments on commit 07cd5ff

Please sign in to comment.