Skip to content

Commit

Permalink
Update the ESLint 9
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesrosiers committed Nov 12, 2024
1 parent 5b76969 commit 25eb3a3
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 229 deletions.
177 changes: 0 additions & 177 deletions .eslintrc.json

This file was deleted.

8 changes: 4 additions & 4 deletions bundle/test-utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type TestCase = {
};

type Test = {
description: string,
instance: Json
description: string;
instance: Json;
};

export const testSuite: (path: string) => TestCase[];
Expand All @@ -22,6 +22,6 @@ export const isCompatible: (compatibility: string | undefined, versionUnderTest:
export const loadSchemas: (testCase: TestCase, retrievalUri: string, dialect: string) => void;
export const unloadSchemas: (testCase: TestCase, retrievalUri: string, dialect: string) => void;
export const toOutput: (instance: JsonNode) => Record<string, {
errors: Record<string>,
annotations: Record<string, Record<string, string>>
errors: Record<string>;
annotations: Record<string, Record<string, string>>;
}>;
2 changes: 1 addition & 1 deletion draft-04/json-schema-test-suite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Test = {
// is usually because there has been some tradeoff I've made to not support
// something that doesn't come up in real schemas in favor of something that has
// value.
const skip: Set<string> = new Set([
const skip = new Set<string>([
// Skip tests for pointers that cross schema resource boundaries. There might
// be a way to solve this, but because this functionality has been removed
// from the spec and there is no good reason to do this, it will probably not
Expand Down
2 changes: 1 addition & 1 deletion draft-06/json-schema-test-suite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Test = {
// is usually because there has been some tradeoff I've made to not support
// something that doesn't come up in real schemas in favor of something that has
// value.
const skip: Set<string> = new Set([
const skip = new Set<string>([
// Skip tests for pointers that cross schema resource boundaries. There might
// be a way to solve this, but because this functionality has been removed
// from the spec and there is no good reason to do this, it will probably not
Expand Down
2 changes: 1 addition & 1 deletion draft-07/json-schema-test-suite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Test = {
// is usually because there has been some tradeoff I've made to not support
// something that doesn't come up in real schemas in favor of something that has
// value.
const skip: Set<string> = new Set([
const skip = new Set<string>([
// Skip tests for pointers that cross schema resource boundaries. There might
// be a way to solve this, but because this functionality has been removed
// from the spec and there is no good reason to do this, it will probably not
Expand Down
2 changes: 1 addition & 1 deletion draft-2019-09/json-schema-test-suite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Test = {
// This package is indended to be a compatibility mode from stable JSON Schema.
// Some edge cases might not work exactly as specified, but it should work for
// any real-life schema.
const skip: Set<string> = new Set([
const skip = new Set<string>([
// Self-identifying with a `file:` URI is not allowed for security reasons.
"|draft2019-09|ref.json|$id with file URI still resolves pointers - *nix",
"|draft2019-09|ref.json|$id with file URI still resolves pointers - windows"
Expand Down
2 changes: 1 addition & 1 deletion draft-2020-12/json-schema-test-suite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Test = {
// This package is indended to be a compatibility mode from stable JSON Schema.
// Some edge cases might not work exactly as specified, but it should work for
// any real-life schema.
const skip: Set<string> = new Set([
const skip = new Set<string>([
// Self-identifying with a `file:` URI is not allowed for security reasons.
"|draft2020-12|ref.json|$id with file URI still resolves pointers - *nix",
"|draft2020-12|ref.json|$id with file URI still resolves pointers - windows"
Expand Down
66 changes: 66 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import js from "@eslint/js";
import stylistic from "@stylistic/eslint-plugin";
import importPlugin from "eslint-plugin-import";
import globals from "globals";
import tseslint from "typescript-eslint";


export default [
js.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
importPlugin.flatConfigs.recommended,
stylistic.configs.customize({
arrowParens: true,
braceStyle: "1tbs",
commaDangle: "never",
flat: true,
jsx: false,
quotes: "double",
semi: true
}),
{
languageOptions: {
ecmaVersion: "latest",
globals: {
...globals.node
},
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname
}
},
settings: {
"import/resolver": {
node: {},
typescript: {}
}
},
rules: {
// JavaScript
"no-console": ["error"],
"no-empty-function": "off",
"no-fallthrough": "off",

// TypeScript
"@typescript-eslint/no-unused-vars": ["error", { caughtErrorsIgnorePattern: "^_" }],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/consistent-type-definitions": ["error", "type"],

// Imports
"import/extensions": ["error", "ignorePackages"],
"import/newline-after-import": ["error", { count: 2, exactCount: false, considerComments: true }],

// Stylistic
"@stylistic/multiline-ternary": "off",
"@stylistic/no-mixed-operators": "off",
"@stylistic/no-multiple-empty-lines": ["error", { max: 2, maxEOF: 0, maxBOF: 0 }], // Allow max=2 for imports
"@stylistic/quote-props": ["error", "consistent"],
"@stylistic/yield-star-spacing": ["error", "after"]
}
},
{
files: ["**/*.js"],
...tseslint.configs.disableTypeChecked
}
];
3 changes: 2 additions & 1 deletion lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export const jsonTypeOf = (value) => {
} else if (Object.getPrototypeOf(value) === Object.prototype) {
return "object";
}
default:
default: {
const type = jsType === "object" ? Object.getPrototypeOf(value).constructor.name || "anonymous" : jsType;
throw Error(`Not a JSON compatible type: ${type}`);
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions lib/experimental.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const getKeywordName: (dialectId: string, keywordId: string) => string;
export const getKeyword: <A>(id: string) => Keyword<A>;
export const getKeywordByName: <A>(keywordName: string, dialectId: string) => Keyword<A>;
export const getKeywordId: (keywordName: string, dialectId: string) => string;
export const defineVocabulary: (id: string, keywords: { [keyword: string]: string }) => void;
export const loadDialect: (dialectId: string, dialect: { [vocabularyId: string]: boolean }, allowUnknownKeywords?: boolean) => void;
export const defineVocabulary: (id: string, keywords: Record<string, string>) => void;
export const loadDialect: (dialectId: string, dialect: Record<string, boolean>, allowUnknownKeywords?: boolean) => void;
export const unloadDialect: (dialectId: string) => void;
export const hasDialect: (dialectId: string) => boolean;

Expand Down
2 changes: 1 addition & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Json } from "@hyperjump/json-pointer";


export type SchemaFragment = string | number | boolean | null | SchemaObject | SchemaFragment[];
export type SchemaObject = {
export type SchemaObject = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
[keyword: string]: SchemaFragment;
};

Expand Down
9 changes: 6 additions & 3 deletions lib/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export const fromJs = (value, uri = "", pointer = "", parent = undefined) => {
} else if (value instanceof Reference) {
return fromJs(value.toJSON(), uri, pointer, parent);
}
default:
default: {
const type = jsType === "object" ? Object.getPrototypeOf(value).constructor.name || "anonymous" : jsType;
throw Error(`Not a JSON compatible type: ${type}`);
}
}
};

Expand Down Expand Up @@ -77,14 +78,16 @@ export const has = (key, node) => key in node.value;

export const step = (key, node) => {
switch (node.type) {
case "object":
case "object": {
const property = node.children.find((propertyNode) => {
return value(propertyNode.children[0]) === key;
});
return property?.children[1];
case "array":
}
case "array": {
const index = parseInt(key, 10);
return node.children[index];
}
default:
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const schemaPlugin = {

return buildSchemaDocument(await response.json(), response.url, contextDialectId);
},
fileMatcher: (path) => /(\.|\/)schema\.json$/.test(path)
fileMatcher: async (path) => /(\.|\/)schema\.json$/.test(path)
};

const schemaRegistry = {};
Expand Down
Loading

0 comments on commit 25eb3a3

Please sign in to comment.