Skip to content

Commit

Permalink
Switch from eslint-plugin-prettier to running prettier directly (#9058)
Browse files Browse the repository at this point in the history
* Switch from eslint-plugin-prettier to running prettier directly

1. Better DX
2. Faster
3. Less infrastructure that can break

* Ignore public folders but keep the current changes

* pnpm lint:prettier:fix

* Format on save

* Bump floating-dependencies timeout

* Fix peer-dep warning

* Lessen spew in prettier output

Co-authored-by: Chris Thoburn <[email protected]>

---------

Co-authored-by: Chris Thoburn <[email protected]>
  • Loading branch information
gitKrystan and runspired authored Oct 26, 2023
1 parent a8f8630 commit c0570ab
Show file tree
Hide file tree
Showing 53 changed files with 387 additions and 548 deletions.
54 changes: 13 additions & 41 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"extends": ["config:base"],
"labels": [":dependabot:", ":label: dependencies"],
"packageRules": [
{
"matchPackagePatterns": [
"@types",
"typescript",
"eslint-config-prettier",
"eslint",
"glint",
"lint",
"prettier",
"stylelint"
"stylelint",
"typescript"
],
"groupName": "code-quality"
},
Expand All @@ -36,10 +35,7 @@
"ember-cli-sri",
"ember-css-modules"
],
"matchPackagePatterns": [
"@embroider",
"postcss"
],
"matchPackagePatterns": ["@embroider", "postcss"],
"groupName": "build-tools"
},
{
Expand All @@ -53,23 +49,12 @@
"ember-page-title",
"tracked-built-ins"
],
"matchPackagePatterns": [
"glimmer",
"polyfill"
],
"matchPackagePatterns": ["glimmer", "polyfill"],
"groupName": "ember-core"
},
{
"matchPackageNames": [
"ember-cli-babel",
"ember-cli-htmlbars",
"@embroider/macros",
"ember-cli-terser"
],
"matchPackagePatterns": [
"babel",
"postcss"
],
"matchPackageNames": ["ember-cli-babel", "ember-cli-htmlbars", "@embroider/macros", "ember-cli-terser"],
"matchPackagePatterns": ["babel", "postcss"],
"groupName": "asset-compilation"
},
{
Expand All @@ -88,24 +73,15 @@
"@ember/test-helpers",
"@ember/test-waiters"
],
"matchPackagePatterns": [
"percy",
"quality",
"test"
],
"matchPackagePatterns": ["percy", "quality", "test"],
"groupName": "testing"
},
{
"matchPackageNames": [
"ember-inflector",
"ember-promise-helpers"
],
"matchPackageNames": ["ember-inflector", "ember-promise-helpers"],
"groupName": "data-utils"
},
{
"matchManagers": [
"github-actions"
],
"matchManagers": ["github-actions"],
"groupName": "github-actions"
}
],
Expand All @@ -115,13 +91,9 @@
"rangeStrategy": "bump",
"prHourlyLimit": 10,
"vulnerabilityAlerts": {
"labels": [
":label: security"
],
"labels": [":label: security"],
"automerge": false,
"assignees": [
"@runspired"
],
"assignees": ["@runspired"],
"enabled": true
},
"ignorePaths": ["node_modules/**", "**/node_modules/**"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compat-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
env:
UV_USE_IO_URING: 0
floating-dependencies:
timeout-minutes: 7
timeout-minutes: 8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
restore-lint-caches: true
install: true
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Prettier
run: pnpm lint:prettier
- name: Lint
run: pnpm lint
- name: Check Uncompiled Packages for TypeScript Compilation Errors
Expand Down
24 changes: 24 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# In addition to gitignore...

# generated files
pnpm-lock.yaml

# we disagree with prettier and we are even more opinionated than they are
*.hbs
*.html
*.md

# these files would be YUGE if we prettified them
MOCK_DATA.json
.mock-cache/

# unconventional
blueprints/
vendor/

# prettier is reporting syntax errors in these
*.yml

# we don't really care about these
main/public/
tests/fastboot/public/
13 changes: 10 additions & 3 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module.exports = {
singleQuote: true,
trailingComma: 'es5',
printWidth: 120
}
printWidth: 120,
overrides: [
{
files: '*.{js,ts,cjs,cts,mjs,mts}',
options: {
singleQuote: true,
},
},
],
};
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"files.associations": {
"turbo.json": "jsonc"
},
"eslint.workingDirectories": [{ "mode": "auto" }, "packages/*", "tests/*"]
"eslint.workingDirectories": [{ "mode": "auto" }, "packages/*", "tests/*"],
"editor.formatOnSave": true
}
17 changes: 12 additions & 5 deletions @types/ember-data-qunit-asserts/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CacheOperation, NotificationType } from "@ember-data/store/-private/managers/notification-manager";
import type { StableDocumentIdentifier } from "@ember-data/store/-types/cache/identifier";
import type { StableRecordIdentifier } from "@warp-drive/core-types";
import type { CacheOperation, NotificationType } from '@ember-data/store/-private/managers/notification-manager';
import type { StableDocumentIdentifier } from '@ember-data/store/-types/cache/identifier';
import type { StableRecordIdentifier } from '@warp-drive/core-types';

declare global {
interface DeprecationConfig {
Expand All @@ -20,7 +20,11 @@ declare global {

interface Assert {
expectDeprecation(options: DeprecationConfig, label?: string): void;
expectDeprecation(callback: () => void | Promise<void>, options: DeprecationConfig | string | RegExp, label?: string): Promise<void>;
expectDeprecation(
callback: () => void | Promise<void>,
options: DeprecationConfig | string | RegExp,
label?: string
): Promise<void>;
expectNoDeprecation(
callback: () => void | Promise<void>,
label?: string,
Expand Down Expand Up @@ -56,7 +60,10 @@ declare global {
namespace QUnit {
export interface Assert {
expectDeprecation(options: { id: string; count: number; until?: string }): void;
expectDeprecation(callback: () => void | Promise<void>, options: DeprecationConfig | string | RegExp): Promise<void>;
expectDeprecation(
callback: () => void | Promise<void>,
options: DeprecationConfig | string | RegExp
): Promise<void>;
expectNoDeprecation(
callback: () => void | Promise<void>,
label?: string,
Expand Down
29 changes: 5 additions & 24 deletions config/eslint/base.cjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
const path = require('path');

let isRoot = false;
try {
const dir = process.cwd();
const pkg = require(path.join(dir, './package.json'));
if (pkg.name === 'root') {
isRoot = true;
}
} catch (e) {
console.log(e);
}

const prettierPath = path.join(process.cwd(), isRoot ? './.prettierrc.js' : '../../.prettierrc.js');
const prettierConfig = require(prettierPath);

function rules() {
return {
eqeqeq: 'error',
Expand All @@ -31,23 +17,18 @@ function rules() {

'prefer-rest-params': 'off',
'prefer-const': 'error',

'prettier/prettier': [
'error',
prettierConfig,
{
usePrettierrc: false,
},
],
};
}

function plugins() {
return ['prettier'];
return [];
}

function extend() {
return ['eslint:recommended', 'plugin:prettier/recommended'];
return [
'eslint:recommended',
'prettier', // NOTE: must be last
];
}

function settings() {
Expand Down
2 changes: 1 addition & 1 deletion config/eslint/ignore.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ function ignoreRules(allowAddon) {
}

module.exports = {
ignoreRules
ignoreRules,
};
16 changes: 8 additions & 8 deletions config/eslint/isolation.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ const RESTRICTED_IMPORTS = [
'ember-source/types',
'ember',
'qunit',
'testem'
'testem',
];
function rules(options) {
return {
'no-restricted-imports': [
'error',
{
paths: options?.allowedImports ? RESTRICTED_IMPORTS.filter(
(path) => {
return !options.allowedImports.includes(path)
}
) : RESTRICTED_IMPORTS,
paths: options?.allowedImports
? RESTRICTED_IMPORTS.filter((path) => {
return !options.allowedImports.includes(path);
})
: RESTRICTED_IMPORTS,
},
],
'no-restricted-globals': [
Expand All @@ -61,9 +61,9 @@ function rules(options) {
message: 'Please use the `qunit` import instead of referencing `QUnit` directly.',
},
],
}
};
}

module.exports = {
rules
rules,
};
56 changes: 28 additions & 28 deletions config/eslint/typescript.cjs
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
function rules(config) {
return Object.assign({
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unused-vars': ['error', { args: 'none' }],
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'no-unused-vars': 'off',
'prefer-const': 'error',
'prefer-rest-params': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'no-loop-func': 'off',
'@typescript-eslint/no-loop-func': 'error',
'no-throw-literal': 'off',
'@typescript-eslint/no-throw-literal': 'error',
// '@typescript-eslint/prefer-readonly-parameter-types': 'error',
}, config?.rules ?? {});
return Object.assign(
{
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unused-vars': ['error', { args: 'none' }],
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'no-unused-vars': 'off',
'prefer-const': 'error',
'prefer-rest-params': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'no-loop-func': 'off',
'@typescript-eslint/no-loop-func': 'error',
'no-throw-literal': 'off',
'@typescript-eslint/no-throw-literal': 'error',
// '@typescript-eslint/prefer-readonly-parameter-types': 'error',
},
config?.rules ?? {}
);
}

function plugins() {
return ['@typescript-eslint'];
}

function extend() {
return [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
];
return ['plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking'];
}

function settings() {
Expand All @@ -38,9 +38,9 @@ function settings() {
parserOptions: {
sourceType: 'module',
ecmaVersion: 2022,
project: 'tsconfig.json'
}
}
project: 'tsconfig.json',
},
};
}

function defaults(config) {
Expand All @@ -59,4 +59,4 @@ module.exports = {
defaults,
plugins,
extend,
}
};
2 changes: 0 additions & 2 deletions config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-n": "^16.2.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"prettier": "^3.0.3",
"typescript": "~5.2.2"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion config/rollup/external.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ function external(manual = []) {

module.exports = {
external,
}
};
Loading

0 comments on commit c0570ab

Please sign in to comment.