Skip to content

Commit

Permalink
feat: eslint-plugin-(ember-data|warp-drive) (#9541)
Browse files Browse the repository at this point in the history
* feat: bump eslint and add eslint-plugin-warp-drive

* fix lockfile

* fix prettier
  • Loading branch information
runspired authored Oct 18, 2024
1 parent e9ea37f commit 0d427d4
Show file tree
Hide file tree
Showing 84 changed files with 2,074 additions and 338 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ project tested against at the point of release.
| [@warp-drive/diagnostic](./packages/diagnostic#readme) | 🌌 | ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/@warp-drive/diagnostic/lts-4-12?label&color=bbbbbb) | ![NPM LTS Version](https://img.shields.io/npm/v/@warp-drive/diagnostic/lts?label&color=0096ff) | ![NPM Stable Version](https://img.shields.io/npm/v/@warp-drive/diagnostic/latest?label&color=90EE90) | ![NPM Beta Version](https://img.shields.io/npm/v/@warp-drive/diagnostic/beta?label&color=ff00ff) | ![NPM Canary Version](https://img.shields.io/npm/v/@warp-drive/diagnostic/canary?label&color=FFBF00) |
| [@warp-drive/ember](./packages/ember#readme) | 🐹 | ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/@warp-drive/ember/lts-4-12?label&color=bbbbbb) | ![NPM LTS Version](https://img.shields.io/npm/v/@warp-drive/ember/lts?label&color=0096ff) | ![NPM Stable Version](https://img.shields.io/npm/v/@warp-drive/ember/latest?label&color=90EE90) | ![NPM Beta Version](https://img.shields.io/npm/v/@warp-drive/ember/beta?label&color=ff00ff) | ![NPM Canary Version](https://img.shields.io/npm/v/@warp-drive/ember/canary?label&color=FFBF00) |
| [@warp-drive/experiments](./packages/experiments#readme) | 🌌 | ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/@warp-drive/experiments/lts-4-12?label&color=bbbbbb) | ![NPM LTS Version](https://img.shields.io/npm/v/@warp-drive/experiments/lts?label&color=0096ff) | ![NPM Stable Version](https://img.shields.io/npm/v/@warp-drive/experiments/latest?label&color=90EE90) | ![NPM Beta Version](https://img.shields.io/npm/v/@warp-drive/experiments/beta?label&color=ff00ff) | ![NPM Canary Version](https://img.shields.io/npm/v/@warp-drive/experiments/canary?label&color=FFBF00) |
| [eslint-plugin-ember-data](./packages/eslint-plugin-ember-data#readme) | 🌌 | ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/eslint-plugin-ember-data/lts-4-12?label&color=bbbbbb) | ![NPM LTS Version](https://img.shields.io/npm/v/eslint-plugin-ember-data/lts?label&color=0096ff) | ![NPM Stable Version](https://img.shields.io/npm/v/eslint-plugin-ember-data/latest?label&color=90EE90) | ![NPM Beta Version](https://img.shields.io/npm/v/eslint-plugin-ember-data/beta?label&color=ff00ff) | ![NPM Canary Version](https://img.shields.io/npm/v/eslint-plugin-ember-data/canary?label&color=FFBF00) |
| [eslint-plugin-warp-drive](./packages/eslint-plugin-warp-drive#readme) | 🌌 | ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/eslint-plugin-warp-drive/lts-4-12?label&color=bbbbbb) | ![NPM LTS Version](https://img.shields.io/npm/v/eslint-plugin-warp-drive/lts?label&color=0096ff) | ![NPM Stable Version](https://img.shields.io/npm/v/eslint-plugin-warp-drive/latest?label&color=90EE90) | ![NPM Beta Version](https://img.shields.io/npm/v/eslint-plugin-warp-drive/beta?label&color=ff00ff) | ![NPM Canary Version](https://img.shields.io/npm/v/eslint-plugin-warp-drive/canary?label&color=FFBF00) |
| [@ember-data/graph](./packages/graph#readme) | 🌌 | ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/@ember-data/graph/lts-4-12?label&color=bbbbbb) | ![NPM LTS Version](https://img.shields.io/npm/v/@ember-data/graph/lts?label&color=0096ff) | ![NPM Stable Version](https://img.shields.io/npm/v/@ember-data/graph/latest?label&color=90EE90) | ![NPM Beta Version](https://img.shields.io/npm/v/@ember-data/graph/beta?label&color=ff00ff) | ![NPM Canarye Version](https://img.shields.io/npm/v/@ember-data/graph/canary?label&color=FFBF00) |
| [@warp-drive/holodeck](./packages/holodeck#readme) | 🌌 | ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/@warp-drive/holodeck/lts-4-12?label&color=bbbbbb) | ![NPM LTS Version](https://img.shields.io/npm/v/@warp-drive/holodeck/lts?label&color=0096ff) | ![NPM Stable Version](https://img.shields.io/npm/v/@warp-drive/holodeck/latest?label&color=90EE90) | ![NPM Beta Version](https://img.shields.io/npm/v/@warp-drive/holodeck/beta?label&color=ff00ff) | ![NPM Canary Version](https://img.shields.io/npm/v/@warp-drive/holodeck/canary?label&color=FFBF00) |
| [@ember-data/json-api](./packages/json-api#readme) | 🌌🐹 | ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/@ember-data/json-api/lts-4-12?label&color=bbbbbb) | ![NPM LTS Version](https://img.shields.io/npm/v/@ember-data/json-api/lts?label&color=0096ff) | ![NPM Stable Version](https://img.shields.io/npm/v/@ember-data/json-api/latest?label&color=90EE90) | ![NPM Beta Version](https://img.shields.io/npm/v/@ember-data/json-api/beta?label&color=ff00ff) | ![NPM Canary Version](https://img.shields.io/npm/v/@ember-data/json-api/canary?label&color=FFBF00) |
Expand Down
1 change: 1 addition & 0 deletions config/eslint/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const RULES = [
'.git/*',
'.broccoli-cache/*',
'unstable-preview-types/*',
'vite.config.mjs.timestamp-*',

// # Special Cases
'docs/*',
Expand Down
1 change: 1 addition & 0 deletions config/eslint/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function esm(config) {
'diagnostic.js',
'diagnostic.mjs',
'eslint.config.mjs',
'vite.config.mjs',
'holodeck.js',
'holodeck.mjs',
'rollup.config.mjs',
Expand Down
4 changes: 3 additions & 1 deletion config/eslint/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function rules(config = {}) {
'@typescript-eslint/no-import-type-side-effects': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-meaningless-void-operator': 'error',
'@typescript-eslint/no-throw-literal': 'error',
'@typescript-eslint/only-throw-error': 'error',
// Many failures for these; they seem intentional so I don't want to just auto-fix:
// '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
// '@typescript-eslint/no-unnecessary-condition': 'error',
Expand Down Expand Up @@ -123,6 +123,8 @@ export function browser(config) {
parser: parser(),
parserOptions: {
project: './tsconfig.json',
// projectService: true,
// tsconfigRootDir: import.meta.dirname,
extraFileExtensions: ['.gts', '.gjs'],
},
/** @type {2022} */
Expand Down
21 changes: 11 additions & 10 deletions config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
"dependencies": {
"@babel/cli": "^7.24.5",
"@babel/core": "^7.24.5",
"@babel/eslint-parser": "7.25.8",
"@rollup/plugin-babel": "^6.0.4",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"typescript-eslint": "^7.13.0",
"@typescript-eslint/eslint-plugin": "^8.10.0",
"@typescript-eslint/parser": "^8.10.0",
"typescript-eslint": "^8.10.0",
"@embroider/addon-dev": "^4.3.1",
"@eslint/js": "^8.57.0",
"globals": "^15.2.0",
"ember-eslint-parser": "^0.4.3",
"eslint": "^8.57.0",
"ember-eslint-parser": "^0.5.2",
"eslint": "^9.12.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-mocha": "^10.4.3",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-qunit": "^8.1.1",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-n": "^17.11.0",
"eslint-plugin-qunit": "^8.1.2",
"eslint-plugin-simple-import-sort": "^12.1.1",
"rollup": "^4.17.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/-ember-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"@ember/test-helpers": "^3.3.0",
"@warp-drive/internal-config": "workspace:5.4.0-alpha.112",
"ember-source": "~5.8.0",
"eslint": "^8.57.0",
"eslint": "^9.12.0",
"pnpm-sync-dependencies-meta-injected": "0.0.14",
"vite": "^5.2.11",
"typescript": "^5.4.5",
Expand Down
2 changes: 2 additions & 0 deletions packages/-warp-drive/src/-private/shared/the-big-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ export const Main = [
'@warp-drive/ember',
'@warp-drive/holodeck',
'@warp-drive/schema-record',
'@warp-drive/experiments',
'@warp-drive/schema',
'ember-data',
'eslint-plugin-ember-data',
'eslint-plugin-warp-drive',
'warp-drive',
];

Expand Down
7 changes: 2 additions & 5 deletions packages/adapter/src/-private/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from '@warp-drive/build-config/macros';

type FetchFunction = (input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
type FetchFunction = (input: RequestInfo, init?: RequestInit) => Promise<Response>;

let _fetch: (() => FetchFunction) | null = null;
type MockRequest = { protocol?: string; get(key: string): string | undefined };
Expand All @@ -26,7 +26,6 @@ export function getFetchFunction(): FetchFunction {
const httpRegex = /^https?:\/\//;
const protocolRelativeRegex = /^\/\//;

// eslint-disable-next-line no-inner-declarations
function parseRequest(request: MockRequest) {
if (request === null) {
throw new Error(
Expand All @@ -38,7 +37,6 @@ export function getFetchFunction(): FetchFunction {
return [request.get('host'), protocol];
}

// eslint-disable-next-line no-inner-declarations
function buildAbsoluteUrl(url: string) {
if (protocolRelativeRegex.test(url)) {
const [host] = parseRequest(REQUEST);
Expand All @@ -50,7 +48,6 @@ export function getFetchFunction(): FetchFunction {
return url;
}

// eslint-disable-next-line no-inner-declarations
function patchedFetch(input: string | { href: string } | RequestInfo, options?: RequestInit) {
if (input && typeof input === 'object' && 'href' in input) {
const url = buildAbsoluteUrl(input.href);
Expand All @@ -65,7 +62,7 @@ export function getFetchFunction(): FetchFunction {
}

_fetch = () => patchedFetch;
} catch (e) {
} catch {
throw new Error(`Unable to create a compatible 'fetch' for FastBoot with node-fetch`);
}
}
Expand Down
8 changes: 6 additions & 2 deletions packages/adapter/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {
if (response.ok && !(payload instanceof Error)) {
return fetchSuccessHandler(this, payload, response, requestData);
} else {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw fetchErrorHandler(this, payload, response, null, requestData);
}
} else {
Expand Down Expand Up @@ -1180,7 +1180,7 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {

try {
json = JSON.parse(responseText);
} catch (e) {
} catch {
// ignored
}

Expand Down Expand Up @@ -1281,6 +1281,7 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {
}
}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface RESTAdapter extends MixtBuildURLMixin {}

function ajaxSuccess(
Expand All @@ -1293,10 +1294,12 @@ function ajaxSuccess(
try {
response = adapter.handleResponse(responseData.status, responseData.headers, payload, requestData);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
return Promise.reject(error);
}

if (response && response.isAdapterError) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
return Promise.reject(response);
} else {
return response;
Expand Down Expand Up @@ -1526,6 +1529,7 @@ function execjQAjax(

hash.error = function (jqXHR, textStatus, errorThrown: Error | string) {
const error = ajaxErrorHandler(adapter, jqXHR, errorThrown, requestData);
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject(error);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@types/bun": "^1.1.4",
"@types/jscodeshift": "0.11.11",
"@warp-drive/internal-config": "workspace:5.4.0-alpha.112",
"eslint": "^8.57.0",
"eslint": "^9.12.0",
"pnpm-sync-dependencies-meta-injected": "0.0.14",
"qunit": "^2.20.1"
},
Expand Down
1 change: 1 addition & 0 deletions packages/diagnostic/server/bun/fetch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable n/no-unsupported-features/node-builtins */
import chalk from 'chalk';
import path from 'path';

Expand Down
1 change: 1 addition & 0 deletions packages/diagnostic/src/-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface Diagnostic {
satisfies<T extends object, J extends T>(actual: J, expected: T, message?: string): void;
}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface TestContext {}

export type GlobalCallback = () => void | Promise<void>;
Expand Down
5 changes: 5 additions & 0 deletions packages/diagnostic/src/internals/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ export async function runTest<TC extends TestContext>(
testReport.start = instrument() && performance.mark(`test:${test.module.moduleName} > ${test.name}:start`);
const Assert = new Diagnostic(DelegatingReporter, Config, test, testReport);

// eslint-disable-next-line @typescript-eslint/no-unused-expressions
groupLogs() && console.groupCollapsed(test.name);
DelegatingReporter.onTestStart(testReport);

if (test.skip) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
groupLogs() && console.groupEnd();
testReport.end = instrument() && performance.mark(`test:${test.module.moduleName} > ${test.name}:end`);
testReport.measure =
Expand Down Expand Up @@ -93,6 +95,7 @@ export async function runTest<TC extends TestContext>(
}
Assert._finalize();

// eslint-disable-next-line @typescript-eslint/no-unused-expressions
groupLogs() && console.groupEnd();
testReport.end = instrument() && performance.mark(`test:${test.module.moduleName} > ${test.name}:end`);
testReport.measure =
Expand All @@ -112,6 +115,7 @@ export async function runModule<TC extends TestContext>(
return;
}

// eslint-disable-next-line @typescript-eslint/no-unused-expressions
groupLogs() && console.groupCollapsed(module.name);
const moduleReport: ModuleReport = {
name: module.moduleName,
Expand Down Expand Up @@ -178,6 +182,7 @@ export async function runModule<TC extends TestContext>(
for (const hook of Config.globalHooks.afterModule) {
await hook();
}
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
groupLogs() && console.groupEnd();
moduleReport.end = instrument() && performance.mark(`module:${module.moduleName}:end`);
moduleReport.measure =
Expand Down
4 changes: 3 additions & 1 deletion packages/diagnostic/src/legacy/equiv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call,@typescript-eslint/ban-types,@typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access */
/*
* The utils below are from QUnit to support deepEqual.
*/
Expand Down Expand Up @@ -276,6 +276,7 @@ const entryTypeCallbacks = {
typeof actual.constructor !== 'undefined' &&
typeof actual[i] === 'function' &&
typeof expected[i] === 'function' &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
(actual[i] as Function).toString() === (expected[i] as Function).toString()
) {
continue;
Expand Down Expand Up @@ -303,6 +304,7 @@ const entryTypeCallbacks = {
typeof expected.constructor !== 'undefined' &&
typeof expected[i] === 'function' &&
typeof actual[i] === 'function' &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
(expected[i] as Function).toString() === (actual[i] as Function).toString()
) {
continue;
Expand Down
2 changes: 2 additions & 0 deletions packages/diagnostic/src/reporters/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ export class DOMReporter implements Reporter {
});

if (compatTestReport.failed > 0 || test.result.failed) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.settings.params.debug.value && console.log(test, compatTestReport);
}

this._socket.emit('test-finish', compatTestReport);
} else if (test.result.failed) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.settings.params.debug.value && console.log(test);
}

Expand Down
3 changes: 0 additions & 3 deletions packages/eslint-plugin-ember-data/src/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# eslint-plugin-ember-data Changelog
# eslint-plugin-warp-drive Changelog

## v0.0.2-alpha.71 (2024-06-15)

Expand Down
26 changes: 26 additions & 0 deletions packages/eslint-plugin-warp-drive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# eslint-plugin-warp-drive

> [!TIP]
> This Package is also available as eslint-plugin-ember-data
## Rules

- 🛠️ has Autofix
- 〽️ has Partial Autofix
- ✅ Recommended
- 💜 TypeScript Aware

**🏷️ Categories**

- 🐞 Helps prevent buggy code
- ⚡️ Helps prevent performance issues
- 🏆 Enforces a best practice

| Rule | Description | 🏷️ ||
| ---- | ----------- | -- | -- |
| [no-create-record-rerender](./docs/no-create-record-rerender.md) | Helps avoid patterns that often lead to excess or broken renders | 🐞⚡️ ||
| [no-invalid-relationships](./docs/no-invalid-relationships.md) | Ensures the basic part of relationship configuration is setup appropriately | 🏆 ||
| [no-legacy-request-patterns](./docs/no-legacy-request-patterns.md) | Restricts usage of deprecated or discouraged request patterns | 🏆 ||
| [no-external-request-patterns](./docs/no-external-request-patterns.md) | Restricts usage of discouraged non-warp-drive request patterns | 🏆 ||

## Usage
8 changes: 8 additions & 0 deletions packages/eslint-plugin-warp-drive/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# eslint-plugin-warp-drive

## Rules

- [no-create-record-rerender](./no-create-record-rerender.md)
- [no-invalid-relationships](./no-invalid-relationships.md)
- [no-legacy-request-patterns](./no-legacy-request-patterns.md)
- [no-external-request-patterns](./no-external-request-patterns.md)
Loading

0 comments on commit 0d427d4

Please sign in to comment.