Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable recommendedTypeChecked and add a more structured fixture #72

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ To use this configuration you'll need `eslint.config.js` file in your project ro
+
+ const config = [
+ { ignores: ["src/accessmanagement-api.ts", "src/types/caspeco-navigation"] },
+ {
+ files: ['**/*.ts', '**/*.tsx'],
+ languageOptions: {
+ parserOptions: {
+ project: true,
+ tsconfigRootDir: import.meta.dirname,
+ },
+ },
+ },
+ ...vanillaConfig,
+ ];
+
Expand All @@ -36,6 +45,15 @@ To use this configuration you'll need `eslint.config.js` file in your project ro
+
+ const config = [
+ { ignores: ["src/accessmanagement-api.ts", "src/types/caspeco-navigation"] },
+ {
+ files: ['**/*.ts', '**/*.tsx'],
+ languageOptions: {
+ parserOptions: {
+ project: true,
+ tsconfigRootDir: import.meta.dirname,
+ },
+ },
+ },
+ ...reactConfig,
+ ];
+
Expand Down
16 changes: 16 additions & 0 deletions __tests__/fixtures/react/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import reactConfig from "./../../../src/frontend-react.js";

const config = [
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
...reactConfig
];

export default config;
23 changes: 23 additions & 0 deletions __tests__/fixtures/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ES2020",
"allowJs": true,
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
}
16 changes: 16 additions & 0 deletions __tests__/fixtures/vanilla/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import vanillaConfig from "./../../../src/frontend-vanilla.js";

const config = [
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
...vanillaConfig
];

export default config;
6 changes: 5 additions & 1 deletion __tests__/fixtures/vanilla/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ var unusedFunction = function() {
console.log("I'm not used anywhere!");
};

console.log("Hello")
console.log("Hello")

const x = 1 as any,
y = 1 as any;
const [x] = 1 as any;
Empty file.
23 changes: 23 additions & 0 deletions __tests__/fixtures/vanilla/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ES2020",
"allowJs": true,
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
}
3 changes: 2 additions & 1 deletion __tests__/validate-frontend.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from "vitest";
import eslint from "eslint";
import frontendVanilla from "../src/frontend-vanilla";
import frontendVanilla from "./fixtures/vanilla/eslint.config";
import { assertHasEslintError } from "./helper";

describe("validate frontend config", () => {
Expand All @@ -13,6 +13,7 @@ describe("validate frontend config", () => {

const result = await cli.lintFiles("__tests__/fixtures/vanilla/frontend.ts");
assertHasEslintError(result, "@typescript-eslint/no-unused-vars");
assertHasEslintError(result, "@typescript-eslint/no-unsafe-assignment");
assertHasEslintError(result, "no-var");
});

Expand Down
4 changes: 2 additions & 2 deletions __tests__/validate-react.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, it } from "vitest";
import eslint from "eslint";
import frontendReact from "../src/frontend-react";
import frontendReact from "./fixtures/react/eslint.config";
import { assertHasEslintError } from "./helper";

describe("validate frontend config", () => {
describe("validate react config", () => {
describe("vanilla", () => {
it.skip("validates hooks rules", async function async() {
const cli = new eslint.ESLint({
Expand Down
2 changes: 1 addition & 1 deletion src/frontend-vanilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import eslintConfigPrettier from "eslint-config-prettier";
/** @type {import('eslint').Linter.Config[]} */
const flatConfig = [
js.configs.recommended,
...typescriptEslintConfig.recommended,
...typescriptEslintConfig.recommendedTypeChecked,
{
files: ["**/*.ts", "**/*.tsx"],
ignores: ["**/*.d.ts", "**/dist/**/*", "**/node_modules/**/*"],
Expand Down