@open-turo/eslint-config-typescript 16.0.0-pr-373.9.1.1 → 16.0.0-pr-373.10.1.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.
package/index.cjs CHANGED
@@ -10,6 +10,7 @@ const sonarjsPlugin = require("eslint-plugin-sonarjs");
10
10
  const unicornPlugin = require("eslint-plugin-unicorn");
11
11
  const tseslint = require("typescript-eslint");
12
12
 
13
+ const FILES_JS = "**/*.?([cm])js";
13
14
  const FILES_SRC_EXTENSION = "?([cm])[jt]s?(x)";
14
15
  const FILES_TS = "**/*.?([cm])ts";
15
16
  const FILES_TSX = "**/*.?([cm])tsx";
@@ -27,6 +28,16 @@ const typescriptLanguageOptions = () => ({
27
28
  },
28
29
  });
29
30
 
31
+ const javascriptConfig = (ecmaVersion = "latest") =>
32
+ tseslint.config(eslint.configs.recommended, {
33
+ files: [FILES_JS],
34
+ languageOptions: {
35
+ parserOptions: {
36
+ ecmaVersion,
37
+ },
38
+ },
39
+ });
40
+
30
41
  const importConfig = () =>
31
42
  tseslint.config({
32
43
  extends: [importPlugin.flatConfigs.recommended],
@@ -186,13 +197,14 @@ const ignoresConfig = (ignores = []) =>
186
197
  * @param [options.allowModules] - List of modules to allow in the n/no-unpublished-import rule
187
198
  * @param [options.ignores] - List of patterns to ignore
188
199
  * @param [options.typescript] - Whether to include typescript rules
200
+ * @param [options.ecmaVersion] - The ECMAScript version to use
189
201
  * @returns {ConfigArray}
190
202
  */
191
203
  module.exports = function config(options = {}) {
192
204
  const useTypescript =
193
205
  options.typescript === undefined ? true : options.typescript;
194
206
  return tseslint.config(
195
- eslint.configs.recommended,
207
+ javascriptConfig(options.ecmaVersion),
196
208
  importConfig(),
197
209
  nPluginConfig(options.allowModules),
198
210
  perfectionistPlugin.configs["recommended-alphabetical"],
package/package.json CHANGED
@@ -54,5 +54,5 @@
54
54
  "access": "public"
55
55
  },
56
56
  "repository": "https://github.com/open-turo/eslint-config-typescript",
57
- "version": "16.0.0-pr-373.9.1.1"
57
+ "version": "16.0.0-pr-373.10.1.1"
58
58
  }
package/test/test.spec.js CHANGED
@@ -1,44 +1,52 @@
1
1
  import { loadESLint } from "eslint";
2
2
 
3
3
  describe("validate config", () => {
4
- test.each(["./index.mjs", "./index.cjs", "./recommended.cjs"])(
5
- `load config file in ESLint to validate all rules are correct for %s`,
6
- async (config) => {
7
- const testFileName = "test.js";
8
- const useFlatConfig = !config.includes("recommended");
4
+ const testFileName = "test.js";
5
+ const code = `const foo = 1;\nconsole.log(foo);\n`;
6
+ const parserOptions = {
7
+ projectService: {
8
+ allowDefaultProject: [testFileName],
9
+ },
10
+ };
11
+
12
+ test("the legacy recommended config is correct", async () => {
13
+ const ESLint = await loadESLint({
14
+ useFlatConfig: false,
15
+ });
16
+ const linter = new ESLint({
17
+ overrideConfig: {
18
+ parserOptions,
19
+ },
20
+ overrideConfigFile: "./recommended.cjs",
21
+ });
22
+ const messages = await linter.lintText(code, {
23
+ filePath: testFileName,
24
+ });
25
+ expect(messages[0].messages).toEqual([]);
26
+ expect(messages[0].errorCount).toEqual(0);
27
+ });
28
+
29
+ test.each(["index.mjs", "index.cjs"])(
30
+ `the flat config is correct for %s`,
31
+ async (configFile) => {
9
32
  const ESLint = await loadESLint({
10
- useFlatConfig,
33
+ useFlatConfig: true,
11
34
  });
35
+ const { default: config } = await import(`../${configFile}`);
12
36
  const linter = new ESLint({
13
- overrideConfig: useFlatConfig
14
- ? [
15
- {
16
- files: [testFileName],
17
- languageOptions: {
18
- parserOptions: {
19
- projectService: {
20
- allowDefaultProject: [testFileName],
21
- },
22
- },
23
- },
24
- },
25
- ]
26
- : {
27
- parserOptions: {
28
- projectService: {
29
- allowDefaultProject: [testFileName],
30
- },
31
- },
37
+ baseConfig: config(),
38
+ overrideConfig: [
39
+ {
40
+ files: [testFileName],
41
+ languageOptions: {
42
+ parserOptions,
32
43
  },
33
- // cwd: cwd,
34
- overrideConfigFile: config,
44
+ },
45
+ ],
46
+ });
47
+ const messages = await linter.lintText(code, {
48
+ filePath: testFileName,
35
49
  });
36
- const messages = await linter.lintText(
37
- `const foo = 1;\nconsole.log(foo);\n`,
38
- {
39
- filePath: testFileName,
40
- },
41
- );
42
50
  expect(messages[0].messages).toEqual([]);
43
51
  expect(messages[0].errorCount).toEqual(0);
44
52
  },