Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try fully linting gjs and gts (eslint + template-lint + prettier) #545

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 196 additions & 10 deletions frontend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,203 @@
'use strict';

const { configs } = require('@nullvoxpopuli/eslint-configs');
const { baseConfig: baseNode } = require('@nullvoxpopuli/eslint-configs/configs/node');
function hasDep(depName) {
try {
return Boolean(require.resolve(depName));
} catch (e) {
if (e.message.startsWith(`Cannot find module '${depName}'`)) return false;

const config = configs.ember();
throw e;
}
}

function proposedEmberDefault(personalPreferences) {
let hasTypeScript = hasDep('typescript');
let noPrettier = process.env.NO_PRETTIER;

const configBuilder = {
modules: {
browser: {
get js() {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

every "leaf object" in this structure defines an ESLint "overrides" entry.

Docs here: https://eslint.org/docs/latest/user-guide/configuring/configuration-files#configuration-based-on-glob-patterns

return {
files: [
'{src,app,addon,addon-test-support,tests}/**/*.{gjs,js}',
'tests/dummy/config/deprecation-workflow.js',
'config/deprecation-workflow.js',
],
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
...(noPrettier ? [] : ['plugin:prettier/recommended']),
],
env: {
browser: true,
},
rules: {
...personalPreferences.rules,
},
}
},
get ts() {
if (!hasTypeScript) return;

return {
files: ['{src,app,addon,addon-test-support,tests,types}/**/*.{gts,ts}'],
parser: '@typescript-eslint/parser',
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
...(noPrettier ? [] : ['plugin:prettier/recommended']),
'plugin:@typescript-eslint/recommended',
],
env: {
browser: true,
},
rules: {
// type imports are removed in builds
'@typescript-eslint/consistent-type-imports': 'error',

// prefer inference, but it is recommended to declare
// return types around public API
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',

// Allows placeholder args to still be defined for
// documentation or "for later" purposes
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
...personalPreferences.rules,
},
}
},
get declarations() {
if (!hasTypeScript) return;

return {
files: ['**/*.d.ts'],
extends: [
'eslint:recommended',
...(noPrettier ? [] : ['plugin:prettier/recommended']),
'plugin:@typescript-eslint/recommended',
],
env: {
browser: true,
},
rules: {
'@typescript-eslint/no-empty-interface': 'off'
}
}
}
},
tests: {
get js() {
let browserJS = configBuilder.modules.browser.js;
return {
...browserJS,
files: ['tests/**/*-test.{gjs,js}'],
extends: [...browserJS.extends, 'plugin:qunit/recommended'],
}
},
get ts() {
if (!hasTypeScript) return;

let browserTS = configBuilder.modules.browser.ts;

return {
...browserTS,
files: ['tests/**/*-test.{gts,ts}'],
extends: [...browserTS.extends, 'plugin:qunit/recommended'],
}
},
}
},
commonjs: {
node: {
get js() {
return {
files: [
'./*.{cjs,js}',
'./config/**/*.js',
'./lib/*/index.js',
'./server/**/*.js',
'./blueprints/*/index.js',
],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
rules: {
...personalPreferences.rules,
// this can be removed once the following is fixed
// https://github.com/mysticatea/eslint-plugin-node/issues/77
'node/no-unpublished-require': 'off',
},
}
}
}
}
}

return configBuilder;
}


const personalPreferences = {
rules: {
// const has misleading safety implications
// look in to "liberal let"
'prefer-const': 'off',

// people should know that no return is undefined in JS
'getter-return': ['error', { allowImplicit: true }],

'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: '*', next: 'break' },
{ blankLine: 'always', prev: '*', next: 'block-like' },
{ blankLine: 'always', prev: 'block-like', next: '*' },
{ blankLine: 'always', prev: ['const', 'let'], next: '*' },
{ blankLine: 'always', prev: '*', next: ['const', 'let'] },
{ blankLine: 'any', prev: ['const', 'let'], next: ['const', 'let'] },
{ blankLine: 'any', prev: ['*'], next: ['case'] },
],
},
}

const config = proposedEmberDefault(personalPreferences);

module.exports = {
...config,
root: true,
/**
* No root rules needed, because we define everything with overrides
* so that understanding what set of rules is applied to what files
* is easier to understand.
*
* This can be debugged with
*
* eslint --print-config ./path/to/file
*/
rules: {},
overrides: [
...config.overrides,
{
...baseNode,
files: ['browserstack.testem.js'],
},
],
config.commonjs.node.js,
config.modules.browser.js,
config.modules.browser.ts,
config.modules.browser.declarations,
config.modules.tests.js,
config.modules.tests.ts,
].filter(Boolean),
};
17 changes: 17 additions & 0 deletions frontend/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

module.exports = {
// Personal preference
printWidth: 100,

// Default Ember (proposed)
plugins: ['prettier-plugin-ember-template-tag'],
overrides: [
{
files: '*.{js,ts,gjs,gts}',
options: {
singleQuote: true,
},
},
],
};
6 changes: 4 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"ember-resolver": "^8.0.3",
"ember-source": "^4.7.0",
"ember-template-imports": "^3.3.1",
"ember-template-lint": "~4.4.0",
"ember-template-lint": "^5.0.0-alpha.0",
"ember-template-lint-plugin-prettier": "^4.0.0",
"esbuild-loader": "^2.19.0",
"eslint": "^7.32.0",
Expand All @@ -118,7 +118,8 @@
"fractal-page-object": "^0.3.0",
"loader.js": "^4.7.0",
"onp": "^2.0.3",
"prettier": "^2.3.2",
"prettier": "^2.7.1",
"prettier-plugin-ember-template-tag": "^0.0.3",
"qunit": "^2.19.1",
"qunit-dom": "^2.0.0",
"rollup": "^2.77.2",
Expand Down Expand Up @@ -162,6 +163,7 @@
"ember-repl": "^2.0.63",
"ember-resources": "^5.6.0",
"ember-statechart-component": "6.1.2",
"eslint-plugin-ember": "^11.2.0",
"highlight.js": "^11.6.0",
"highlightjs-glimmer": "^2.0.1",
"html-to-image": "^1.9.0",
Expand Down
1 change: 1 addition & 0 deletions frontend/tests/unit/services/editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module('Unit | Service | editor', function (hooks) {
// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let service = this.owner.lookup('service:editor');

assert.ok(service);
});
});
2 changes: 1 addition & 1 deletion frontend/types/limber/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ember from 'ember';
import type Ember from 'ember';

declare global {
interface Array<T> extends Ember.ArrayPrototypeExtensions<T> {}
Expand Down
Loading