Skip to content

Commit

Permalink
Merge pull request #1 from NullVoxPopuli/fix-linting
Browse files Browse the repository at this point in the history
Fix Eslint + ts configs
  • Loading branch information
NullVoxPopuli authored Jun 24, 2022
2 parents 4bb4139 + 5f5a28a commit 4273014
Show file tree
Hide file tree
Showing 27 changed files with 164 additions and 75 deletions.
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
dist
coverage

# These paths are either already built (and will error due to the type-aware lints not having the paths included in the tsconfig.json)
# or are not built at all (except maybe by vite), and excluded from tsconfig.json
# In any case, excluding paths from tsconfig.json makes them unlintable with
# the type-aware lints.
@types/@domtree/**/*.js
@types/@domtree/**/*.d.ts
packages/x-devtools-extension
100 changes: 64 additions & 36 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"prettier",
"@typescript-eslint",
"unused-imports",
"simple-import-sort"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"project": false,
"sourceType": "module"
},
"settings": {
Expand All @@ -23,56 +22,79 @@
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:json/recommended"
],
"rules": {
"no-restricted-syntax": [
"error",
{
"selector": "TSEnumDeclaration[const=true]",
"message": "const enums are not supported in isolated module mode"
}
],

"import/default": ["warn"],
"import/no-cycle": ["warn"],
"import/no-duplicates": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"@typescript-eslint/consistent-type-imports": [
"error",
{
"prefer": "type-imports"
}
],
"@typescript-eslint/consistent-type-exports": [
"error",
{
"fixMixedExportsWithInlineTypeSpecifier": true
}
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": false,
"caughtErrors": "none",
"argsIgnorePattern": "^_"
}
],
"unused-imports/no-unused-imports": "error",
"no-empty": "warn",
"no-fallthrough": "off",
"prefer-const": "off",
"prefer-arrow-callback": "warn"
},
"overrides": [
{
"files": ["**/*.{ts,tsx}"],
"parser": "@typescript-eslint/parser",
"plugins": [
"prettier",
"@typescript-eslint",
"unused-imports",
"simple-import-sort"
],
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module"
},
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:json/recommended"
],
"rules": {
"no-restricted-syntax": [
"error",
{
"selector": "TSEnumDeclaration[const=true]",
"message": "const enums are not supported in isolated module mode"
}
],

"@typescript-eslint/consistent-type-imports": [
"error",
{
"prefer": "type-imports"
}
],
"@typescript-eslint/consistent-type-exports": [
"error",
{
"fixMixedExportsWithInlineTypeSpecifier": true
}
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": false,
"caughtErrors": "none",
"argsIgnorePattern": "^_"
}
]
}
},
{
"files": ["demos/*/**/*.{tsx,ts}"],
"rules": {
Expand All @@ -83,6 +105,12 @@
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off"
}
},
{
"files": ["framework/react/use-resource/scripts/**/*"],
"env": {
"node": true
}
}
]
}
10 changes: 10 additions & 0 deletions @types/@domtree/any/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const path = require('path');

module.exports = {
root: false,
parserOptions: {
project: require.resolve(path.join(__dirname, './tsconfig.json')),
},
}
3 changes: 3 additions & 0 deletions @types/@domtree/any/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"dependencies": {
"@domtree/browser": "workspace:*",
"@domtree/interface": "workspace:*"
},
"devDependencies": {
"eslint": "^8.16.0"
}
}
13 changes: 13 additions & 0 deletions @types/@domtree/any/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
// this is a type-definitions package,
// we author the types by hand, and are only
// checking validitiy
"noEmit": true
},
"include": [
"*.d.ts",
"*.ts"
]
}
7 changes: 6 additions & 1 deletion @types/@domtree/minimal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export namespace Node {
export type DOCUMENT_FRAGMENT_NODE = 11;
}

type ReadonlyNode = {};
// --- Type utilities for component signatures --- //
// Type-only "symbol" to use with `ReadonlyNode` below, so that it is *not*
// equivalent to an empty interface.
declare const Empty: unique symbol;

type ReadonlyNode = { [Empty]?: true };

interface ReadonlyParent extends ReadonlyNode {
readonly firstChild: ChildNode | null;
Expand Down
1 change: 1 addition & 0 deletions framework/react/react/src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (typeof process === "undefined") {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
globalThis.process = {} as any;
}

Expand Down
1 change: 1 addition & 0 deletions framework/react/react/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ export function ref<E extends browser.Element>(
placeholder as unknown as ElementPlaceholder<browser.Element>
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return refCallback as any;
}
6 changes: 3 additions & 3 deletions framework/react/react/src/stable-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class StableProps<Variables extends AnyRecord> {
static from<Variables extends AnyRecord>(
props: Variables
): StableProps<Variables> {
let internal = Object.fromEntries(
const internal = Object.fromEntries(
Object.entries(props).map(([key, value]) => initialPropEntry(key, value))
) as InternalReactiveProps<Variables>;

Expand All @@ -34,11 +34,11 @@ export class StableProps<Variables extends AnyRecord> {
const proxy = this.#proxy;
let changes = false;

for (let [key, newValue] of Object.entries(newReactProps)) {
for (const [key, newValue] of Object.entries(newReactProps)) {
changes = changes || updateProp(stableProps, proxy, key, newValue);
}

for (let key of Object.keys(stableProps)) {
for (const key of Object.keys(stableProps)) {
if (!(key in newReactProps)) {
delete stableProps[key as keyof Variables];
delete proxy[key as keyof Variables];
Expand Down
2 changes: 2 additions & 0 deletions framework/react/react/src/use-reactive-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export function useReactiveElement<I extends Inputs>(

if (stableProps) {
formula = Formula(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
definition(stableProps.current.reactive as any, element)
);
} else {
Expand Down Expand Up @@ -372,6 +373,7 @@ function useReactiveElementArgs<I extends Inputs>(
): NormalizedArgs<I> {
if (isCompleteArgs(args)) {
const [props, definition, description] = args;
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return { props, definition, description } as any;
}

Expand Down
1 change: 1 addition & 0 deletions framework/react/use-resource/src/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function isState<T, S extends ReactState<T>>(
} else {
const types = Type;

// eslint-disable-next-line no-inner-declarations
function isOneOf<T>(value: ReactState<T>): value is S {
return types.some((type) => type.is(value));
}
Expand Down
8 changes: 4 additions & 4 deletions framework/react/use-resource/src/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ export function parseStack(stack: string): {
header: string[];
stack: string[];
} {
let lines = stack.split("\n");
const lines = stack.split("\n");
let headerDone = false;

let headerLines = [];
let stackLines = [];
const headerLines = [];
const stackLines = [];

for (let line of lines) {
for (const line of lines) {
if (headerDone) {
stackLines.push(line);
} else {
Expand Down
6 changes: 4 additions & 2 deletions framework/react/use-resource/tests/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function render<P>(
...children: ReactNode[]
): ReactElement;
function render(
component: FunctionComponent<{}>,
component: FunctionComponent,
...children: ReactNode[]
): ReactElement;
function render(...args: any): ReactElement {
Expand All @@ -75,6 +75,7 @@ export const react = {
render,
} as const;

/* eslint-disable */
export const html: HtmlProxy = new Proxy(() => {}, {
get: (target, property, receiver) => {
if (typeof property === "symbol") {
Expand All @@ -93,7 +94,8 @@ export const html: HtmlProxy = new Proxy(() => {}, {

apply: (target, receiver, args) => {},
}) as unknown as HtmlProxy;
/* eslint-enable */

export function el(tag: string | FunctionComponent<{}>, children: ReactNode[]) {
export function el(tag: string | FunctionComponent, children: ReactNode[]) {
return createElement(tag, null, ...children);
}
9 changes: 6 additions & 3 deletions framework/react/use-resource/tests/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export class TestElement<E extends Element> {

const fire: Partial<BoundFireObject> = {};

for (let [key, value] of Object.entries(fireEvent)) {
for (const [key, value] of Object.entries(fireEvent)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
fire[key as keyof BoundFireObject] = this.#bind(value);
}

Expand All @@ -82,6 +83,7 @@ export class TestElement<E extends Element> {

#bind(method: FireObject[keyof FireObject]) {
return (...args: any) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const result = method(this.#element, ...args);
entryPoint(() => this.#assert());
return result;
Expand Down Expand Up @@ -224,6 +226,7 @@ export class RenderResult<Props, T> {
return { expecting: this.#postcondition() };
};

// eslint-disable-next-line @typescript-eslint/no-empty-function
deactivate() {}

unmount(): { expecting: RerenderContext<T> } {
Expand Down Expand Up @@ -390,7 +393,7 @@ class RerenderContext<T> {
context.html(expectedHTML);
}

for (let value of context.#current.stableValues) {
for (const value of context.#current.stableValues) {
value.assert(result.value);
}

Expand Down Expand Up @@ -507,7 +510,7 @@ export class Mode {
definition: (props?: Props) => { dom: ReactElement; value: T },
props?: Props
): RenderResult<Props, T> {
let rerender: { current: () => void } = { current: () => null };
const rerender: { current: () => void } = { current: () => null };
let renderCount = 0;
const values: Values<T> = Values.create();

Expand Down
1 change: 1 addition & 0 deletions framework/react/use-resource/tests/updating-ref.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useUpdatingRef } from "../src/updating-ref.js";
import { react } from "./dom.js";
import { testModes } from "./modes.js";

// eslint-disable-next-line @typescript-eslint/require-await
testModes("useUpdatingRef.mutable", async (mode) => {
const result = mode
.render(() => {
Expand Down
1 change: 1 addition & 0 deletions framework/react/use-resource/tests/use-resource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ testModes("useResource (nested, stability across remounting)", (mode) => {
.expectStable((value) => value.current)
.expectHTML(
({ current: { state, count, id } }) =>
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`<p>${state}</p><p>parent:${count}</p><p>child:${count} id:${id}</p><label><span>Increment</span><button>++</button></label>`
);

Expand Down
Loading

0 comments on commit 4273014

Please sign in to comment.