@lipemat/eslint-config 3.4.3 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/helpers/config.js +11 -19
  2. package/index.js +82 -65
  3. package/package.json +21 -11
package/helpers/config.js CHANGED
@@ -1,6 +1,6 @@
1
- const {getExtensionsConfig} = require( '@lipemat/js-boilerplate/helpers/config' );
2
- const {getPackageConfig} = require( '@lipemat/js-boilerplate/helpers/package-config' );
3
- const path = require( 'path' );
1
+ import {getExtensionsConfig} from '@lipemat/js-boilerplate/helpers/config.js';
2
+ import {getPackageConfig} from '@lipemat/js-boilerplate/helpers/package-config.js';
3
+ import path from 'path';
4
4
 
5
5
 
6
6
  /**
@@ -17,22 +17,18 @@ const path = require( 'path' );
17
17
  * @see @lipemat/js-boilerplate/helpers/config
18
18
  *
19
19
  * @example ```ts
20
- * // standard
21
- * module.export = {
22
- * externals: {extra: 'Extra'}
23
- * }
24
20
  * // function
25
- * module.exports = function( config ) {
26
- * return {
27
- * externals: {...config.externals, extra: 'Extra'}
28
- * }
21
+ * module.exports = function( config: { configs: Linter.Config[] } ) {
22
+ * config.configs[0].push({extra: 'Extra'});
23
+ * return config
29
24
  * }
30
25
  * ```
31
26
  *
32
- * @return {Object}
27
+ * @return Linter.Config[]
33
28
  */
34
- function getConfig( mergedConfig ) {
35
- mergedConfig = {...mergedConfig, ...getExtensionsConfig( 'eslint.config', mergedConfig )};
29
+ export function getConfig( mergedConfig ) {
30
+ mergedConfig = getExtensionsConfig( 'eslint.config', {configs: mergedConfig} );
31
+
36
32
  try {
37
33
  const localConfig = require( path.resolve( getPackageConfig().packageDirectory + '/config', 'eslint.config' ) );
38
34
  if ( 'function' === typeof localConfig ) {
@@ -42,9 +38,5 @@ function getConfig( mergedConfig ) {
42
38
  }
43
39
  } catch ( e ) {
44
40
  }
45
- return mergedConfig;
41
+ return mergedConfig.configs;
46
42
  }
47
-
48
- module.exports = {
49
- getConfig,
50
- };
package/index.js CHANGED
@@ -1,70 +1,32 @@
1
+ import {fixupConfigRules} from '@eslint/compat';
2
+ import {FlatCompat} from '@eslint/eslintrc';
3
+ import tsPlugin from '@typescript-eslint/eslint-plugin';
4
+ import tsParser from '@typescript-eslint/parser';
5
+ import globals from 'globals';
6
+ import stylisticTs from '@stylistic/eslint-plugin-ts';
7
+ import {getConfig} from './helpers/config.js';
8
+
9
+
10
+ const flatCompat = new FlatCompat();
11
+
1
12
  /**
2
13
  * Default config if no extensions override it.
3
14
  *
4
15
  */
5
- let mergedConfig = {
6
- env: {
7
- browser: true,
8
- },
9
- extends: [
10
- 'plugin:@wordpress/eslint-plugin/recommended-with-formatting',
11
- 'plugin:deprecation/recommended',
12
- ],
13
- globals: {
14
- $: 'readonly',
15
- jQuery: 'readonly',
16
- },
17
- overrides: [ {
18
- files: [ '**/*.ts', '**/*.tsx' ],
19
- plugins: [
20
- '@typescript-eslint',
21
- ],
22
- //Rules to override the standard JS ones when we get undesired results for TypeScript may be found here
23
- //@link https://typescript-eslint.io/rules/
24
- rules: {
25
- 'jsdoc/no-undefined-types': 'off',
26
- 'no-magic-numbers': 'off',
27
- 'no-redeclare': 'off',
28
- 'no-shadow': 'off',
29
- 'no-undef': 'off',
30
- semi: 'off',
31
- '@typescript-eslint/ban-types': [
32
- 'error',
33
- {
34
- types: {
35
- unknown: 'Use a specific type.',
36
- },
37
- },
38
- ],
39
- '@typescript-eslint/no-explicit-any': 'error',
40
- '@typescript-eslint/no-shadow': [ 'error' ],
41
- '@typescript-eslint/no-redeclare': [ 'error' ],
42
- '@typescript-eslint/no-unused-vars': 'error',
43
- '@typescript-eslint/strict-boolean-expressions': [
44
- 'warn',
45
- {
46
- allowString: false,
47
- allowNumber: false,
48
- },
49
- ],
50
- '@typescript-eslint/type-annotation-spacing': [ 'warn', {
51
- before: false,
52
- after: true,
53
- overrides: {
54
- arrow: {
55
- before: true,
56
- after: true,
57
- },
58
- },
59
- } ],
60
- },
61
- } ],
62
- parser: '@typescript-eslint/parser',
63
- parserOptions: {
16
+ const BASE_CONFIG = {
17
+ languageOptions: {
64
18
  ecmaVersion: 7,
65
- project: './tsconfig.json',
19
+ globals: {
20
+ ...globals.browser,
21
+ $: 'readonly',
22
+ jQuery: 'readonly',
23
+ },
24
+ parser: tsParser,
25
+ parserOptions: {
26
+ project: './tsconfig.json',
27
+ warnOnUnsupportedTypeScriptVersion: false,
28
+ },
66
29
  sourceType: 'module',
67
- warnOnUnsupportedTypeScriptVersion: false,
68
30
  },
69
31
  rules: {
70
32
  'arrow-parens': [ 1, 'as-needed' ],
@@ -79,6 +41,8 @@ let mergedConfig = {
79
41
  // Parse error with Svelte v4 due to `as` operator.
80
42
  'import/named': 'off',
81
43
  'import/no-unresolved': 'off',
44
+ // Parse error with Svelte v4 due to `as` operator.
45
+ 'import/named': 'off',
82
46
  'no-console': [ 'warn', {allow: [ 'warn', 'error', 'debug' ]} ],
83
47
  'no-constant-binary-expression': [ 'warn' ],
84
48
  'no-multiple-empty-lines': [ 'error', {max: 2} ],
@@ -87,7 +51,11 @@ let mergedConfig = {
87
51
  'react/display-name': 'off',
88
52
  'react-hooks/rules-of-hooks': 'error',
89
53
  'react-hooks/exhaustive-deps': 'warn',
90
- 'react/jsx-curly-spacing': [ 1, {when: 'never', allowMultiline: false, children: true} ],
54
+ 'react/jsx-curly-spacing': [ 1, {
55
+ when: 'never',
56
+ allowMultiline: false,
57
+ children: true,
58
+ } ],
91
59
  'react/prop-types': [ 2, {skipUndeclared: true} ],
92
60
  'space-before-blocks': [ 1, 'always' ],
93
61
  'space-before-function-paren': [ 'error', {
@@ -99,7 +67,6 @@ let mergedConfig = {
99
67
  'template-curly-spacing': [ 1, 'never' ],
100
68
  yoda: [ 2, 'always', {onlyEquality: true} ],
101
69
  },
102
- root: true,
103
70
  settings: {
104
71
  react: {
105
72
  version: '18.0',
@@ -107,14 +74,64 @@ let mergedConfig = {
107
74
  },
108
75
  };
109
76
 
77
+
78
+ const TS_CONFIG = {
79
+ files: [ '**/*.ts', '**/*.tsx' ],
80
+ plugins: {
81
+ '@typescript-eslint': tsPlugin,
82
+ '@stylistic/ts': stylisticTs,
83
+ },
84
+ //Rules to override the standard JS ones when we get undesired results for TypeScript may be found here
85
+ //@link https://typescript-eslint.io/rules/
86
+ rules: {
87
+ 'jsdoc/no-undefined-types': 'off',
88
+ 'no-magic-numbers': 'off',
89
+ 'no-redeclare': 'off',
90
+ 'no-shadow': 'off',
91
+ 'no-undef': 'off',
92
+ 'no-unused-vars': 'off',
93
+ semi: 'off',
94
+ '@typescript-eslint/no-empty-object-type': 'error',
95
+ '@typescript-eslint/no-explicit-any': 'error',
96
+ '@typescript-eslint/no-redeclare': [ 'error' ],
97
+ '@typescript-eslint/no-restricted-types': [ 'error', {
98
+ types: {
99
+ unknown: 'Use a specific type.',
100
+ },
101
+ } ],
102
+ '@typescript-eslint/no-shadow': [ 'error' ],
103
+ '@typescript-eslint/no-unsafe-function-type': 'error',
104
+ '@typescript-eslint/no-unused-vars': 'error',
105
+ '@typescript-eslint/no-wrapper-object-types': 'error',
106
+ '@typescript-eslint/strict-boolean-expressions': [ 'warn', {
107
+ allowString: false, allowNumber: false,
108
+ } ],
109
+ '@stylistic/ts/type-annotation-spacing': [ 'warn', {
110
+ before: false,
111
+ after: true,
112
+ overrides: {
113
+ arrow: {
114
+ before: true,
115
+ after: true,
116
+ },
117
+ },
118
+ } ],
119
+ },
120
+ };
121
+
110
122
  /**
111
123
  * Merge in any extensions' config.
112
124
  */
125
+ let mergedConfig = [ BASE_CONFIG, TS_CONFIG ];
113
126
  try {
114
- const {getConfig} = require( './helpers/config' );
115
127
  mergedConfig = getConfig( mergedConfig );
116
128
  } catch ( e ) {
129
+ console.debug( e );
117
130
  // JS Boilerplate is not installed.
118
131
  }
119
132
 
120
- module.exports = mergedConfig;
133
+ export default [
134
+ ...fixupConfigRules( flatCompat.extends( 'plugin:@wordpress/eslint-plugin/recommended-with-formatting' ) ),
135
+ ...fixupConfigRules( flatCompat.extends( 'plugin:deprecation/recommended' ) ),
136
+ ...mergedConfig,
137
+ ];
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@lipemat/eslint-config",
3
- "version": "3.4.3",
3
+ "version": "4.0.0-beta.1",
4
4
  "license": "MIT",
5
5
  "description": "Eslint configuration for all @lipemat packages",
6
6
  "engines": {
7
7
  "node": ">=20.11.0"
8
8
  },
9
+ "type": "module",
9
10
  "main": "index.js",
10
11
  "files": [
11
12
  "index.js",
@@ -23,22 +24,31 @@
23
24
  "test": "lipemat-js-boilerplate test"
24
25
  },
25
26
  "dependencies": {
26
- "@types/eslint": "^8",
27
- "@wordpress/eslint-plugin": "^12.2.0",
28
- "eslint": "^8",
29
- "eslint-plugin-deprecation": "^3.0.0",
30
- "eslint-plugin-jsx-a11y": "6.7.1"
27
+ "@eslint/compat": "^1.2.4",
28
+ "@eslint/eslintrc": "^3.2.0",
29
+ "@stylistic/eslint-plugin-ts": "^2.12.1",
30
+ "@types/eslint": "^9",
31
+ "@typescript-eslint/eslint-plugin": "^8.18.0",
32
+ "@typescript-eslint/parser": "^8.18.0",
33
+ "@wordpress/eslint-plugin": "^22.0.0",
34
+ "eslint": "^9",
35
+ "eslint-plugin-deprecation": "^3",
36
+ "eslint-plugin-import": "^2.31.0",
37
+ "eslint-plugin-jsx-a11y": "6.7.1",
38
+ "globals": "^15.13.0"
31
39
  },
32
40
  "devDependencies": {
33
- "@lipemat/js-boilerplate": "^10.3.1",
34
- "@lipemat/js-boilerplate-svelte": "^0.0.4",
41
+ "@lipemat/js-boilerplate": "^10.10.4",
42
+ "@lipemat/js-boilerplate-svelte": "^1.1.2",
35
43
  "@types/jest": "^29.5.3",
36
- "@types/node": "^16",
44
+ "@types/node": "^20",
45
+ "execa": "^5.1.1",
37
46
  "jest": "^29",
38
- "typescript": "^5.1.6"
47
+ "jest-runner-eslint": "^2.2.1",
48
+ "typescript": "^5.7.2"
39
49
  },
40
50
  "peerDependencies": {
41
51
  "@lipemat/js-boilerplate": "^10.3.1"
42
52
  },
43
- "packageManager": "yarn@4.5.1"
53
+ "packageManager": "yarn@4.5.3"
44
54
  }