Skip to content

Commit

Permalink
change eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryD committed Jan 28, 2024
1 parent 32caaac commit 167a850
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 61 deletions.
124 changes: 71 additions & 53 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,75 @@
'use strict';

/**
* ESLint is really complicated right now, so all of it is abstracted away.
* Updates coming soon (and hopefully to the built-in ember experience).
*/
const { configs } = require('@nullvoxpopuli/eslint-configs');

const config = configs.ember();

const hasTS = (globArray) => globArray.some((glob) => glob.includes('ts'));

// Setup newer TS-aware lints
function addTSProject(override) {
if (!hasTS(override.files)) return override;

return {
...override,
/**
* This is how you tell @typescript-eslint to use your tsconfig.
* However, for gts files, we get this:
*
<repo>/app/components/welcome.gts
0:0 error Parsing error: ESLint was configured to run on
`<tsconfigRootDir>/app/components/welcome.gts/0_<repo>/app/components/welcome.gts/0_<repo>/app/components/welcome.gts/0_<repo>/app/components/welcome.gts`
using `parserOptions.project`: <tsconfigRootDir>/tsconfig.json
However, that TSConfig does not include this file. Either:
- Change ESLint's list of included files to not include this file
- Change that TSConfig to include this file
- Create a new TSConfig that includes this file and include it in your parserOptions.project
This is likely because we need to configure the TS parser to use glint instead of tsc
*/
// parserOptions: {
// ...override.parserOptions,
// extraFileExtensions: [".gts"],
// project: path.join(__dirname, "./tsconfig.json"),
// // TODO: try to set the Glint Program
// // https://typescript-eslint.io/packages/parser/
// // program: import("@glint/core"),
// },
rules: {
...override.rules,
// Disabled until the above issue is resolved
'@typescript-eslint/prefer-optional-chain': 'off',
},
};
}

module.exports = {
...config,
overrides: [...config.overrides].map(addTSProject),
parserOptions: {
"ecmaVersion": "latest",
"sourceType": "module",
}
overrides: [
{
files: ['**/*.{js,ts}'],
plugins: ['ember'],
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:ember/recommended'],
rules: {
'no-unused-vars': 'off',
'no-undef': 'off',
}
},
{
files: ['**/*.gts'],
parser: 'ember-eslint-parser',
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended', 'plugin:ember/recommended-gts'],
rules: {
'no-unused-vars': 'off',
'no-undef': 'off',
}
},
{
files: ['**/*.gjs'],
parser: 'ember-eslint-parser',
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended', 'plugin:ember/recommended-gjs'],
rules: {
'no-unused-vars': 'off',
'no-undef': 'off',
}
},
// test files
{
files: ['tests/**/*-test.{js,ts}'],
plugins: ['ember'],
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:qunit/recommended'],
rules: {
'no-unused-vars': 'off',
'no-undef': 'off',
}
},
{
files: ['tests/**/*-test.{gjs,gts}'],
parser: 'ember-eslint-parser',
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended', 'plugin:ember/recommended-gts'],
},
// node files
{
files: [
'./.eslintrc.{js,cjs}',
'./.prettierrc.{js,cjs}',
'./.stylelintrc.{js,cjs}',
'./.template-lintrc.{js,cjs}',
'./ember-cli-build.js',
'./playwright.config.ts',
'./testem.js',
'./tailwind.config.js',
'./blueprints/*/index.js',
'./config/**/*.js',
'./lib/*/index.js',
'./server/**/*.js',
],
env: {
browser: false,
node: true,
},
extends: ['plugin:n/recommended'],
},
],
};
1 change: 0 additions & 1 deletion app/components/forms/yup-form.gts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function isFieldError(field: string, errorKey: string): boolean {
export interface ChangesetFormComponentSignature {
Args: {
changeset: ImmerChangeset;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSubmit: <T extends ImmerChangeset<any>>(changeset: T) => Promisable<unknown>;
validationSchema: Schema;
removeErrorsOnSubmit?: boolean;
Expand Down
5 changes: 3 additions & 2 deletions app/modifiers/errors-scroll-up.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { later } from '@ember/runloop';

import { runTask } from 'ember-lifeline';
import type { ValidationError } from 'ember-immer-changeset';

export function scrollToFirstError(
target: object,
element: Element | Document,
errors: ValidationError[],
): void {
Expand All @@ -21,7 +22,7 @@ export function scrollToFirstError(
const targetTop =
errorElement.getBoundingClientRect().top + window.scrollY - 85;

later(() => {
runTask(target, () => {
window.scrollTo({ top: targetTop, behavior: 'smooth' });
}, 20);
}
Expand Down
3 changes: 2 additions & 1 deletion app/modifiers/scroll-on-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { scrollToFirstError } from './errors-scroll-up';
import type { ValidationError } from 'ember-immer-changeset';

export default modifier(function scrollOnError(
this: object,
element,
[errors]: [ValidationError[]],
) {
scrollToFirstError(element, errors);
scrollToFirstError(this, element, errors);
});
1 change: 0 additions & 1 deletion app/templates/register.gts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class RegisterRouteComponent extends Component<RegisterRouteComponentSignature>
try {
await this.register.save(changeset);
this.flashMessages.success('components.pages.register.success_message');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
const error = await e;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"ember-flatpickr": "~4.0.0",
"ember-immer-changeset": "~1.0.2",
"ember-intl": "^6.4.0",
"ember-lifeline": "^7.0.0",
"ember-load-initializers": "~2.1.2",
"ember-modifier": "~4.1.0",
"ember-page-title": "~8.2.1",
Expand Down
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions prune.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rm -rf .git
rm -rf .husky
rm -rf .github
1 change: 0 additions & 1 deletion types/ember-data/types/registries/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
* Catch-all for ember-data.
*/
export default interface ModelRegistry {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}
2 changes: 0 additions & 2 deletions types/ember-simple-auth/services/session.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ declare module 'ember-simple-auth/services/session' {
invalidate(): Promise<void>;
requireAuthentication(
transition: Transition,
// eslint-disable-next-line @typescript-eslint/ban-types
routeOrCallback: string | Function
): boolean;
// eslint-disable-next-line @typescript-eslint/ban-types
prohibitAuthentication(routeOrCallback: string | Function): boolean;
handleAuthentication(routeAfterAuthentication: string): void;
handleInvalidation(routeAfterInvalidation: string): void;
Expand Down
1 change: 1 addition & 0 deletions types/template-registry.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@glint/environment-ember-loose';
import '@glint/environment-template-components';

// eslint-disable-next-line ember/no-at-ember-render-modifiers
import type RenderModifiersRegistry from '@ember/render-modifiers/template-registry';
import type EmberInputRegistry from '@triptyk/ember-input/template-registry';
import type EmberInputValidationRegistry from '@triptyk/ember-input-validation/template-registry';
Expand Down

0 comments on commit 167a850

Please sign in to comment.