-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
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), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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