Skip to content

Commit

Permalink
Install dependencies, add configs
Browse files Browse the repository at this point in the history
  • Loading branch information
lolmaus committed Jun 13, 2020
1 parent ce98235 commit 997a85b
Show file tree
Hide file tree
Showing 24 changed files with 2,353 additions and 184 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Expand Up @@ -4,16 +4,17 @@

root = true


[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2
max_line_length = 100

[*.hbs]
insert_final_newline = false

[*.{diff,md}]
trim_trailing_whitespace = false
6 changes: 4 additions & 2 deletions .eslintignore
Expand Up @@ -8,13 +8,15 @@

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

# IDE
/.idea/
/.history/
133 changes: 101 additions & 32 deletions .eslintrc.js
@@ -1,58 +1,127 @@
'use strict';

const nodeFiles = [
'.eslintrc.js',
'.lintstagedrc.js',
'.prettierrc.js',
'.template-lintrc.{js,ts}',
'ember-cli-build.{js,ts}',
'testem.{js,ts}',
'blueprints/*/index.{js,ts}',
'config/**/*.{js,ts}',
'lib/*/index.{js,ts}',
'server/**/*.{js,ts}',
];

const browserFiles = [
'addon/**/*.{js,ts}',
'addon-test-support/**/*.{js,ts}',
'app/**/*.{js,ts}',
'test-support/**/*.{js,ts}',
'types/**/*.{js,ts}',
];

const browserTestFiles = ['tests/**/*.{js,ts}'];

module.exports = {
root: true,
parser: 'babel-eslint',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true
}
project: ['./tsconfig.json', './tsconfig-node.json'],
},
plugins: [
'ember'
],
plugins: ['@typescript-eslint', 'ember', 'prettier'],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:ember/recommended',
'standard',

'prettier/@typescript-eslint',
'prettier/standard',

// This one should come last
'plugin:prettier/recommended',
],
env: {
browser: true
browser: true,
},
rules: {
'ember/no-jquery': 'error'
'@typescript-eslint/ban-ts-ignore': 'off', // Can't fully get rid of it due to TS quirks and issues with third-party depenecies
'@typescript-eslint/camelcase': 'off', // Allow two levels of separation, e. g. ProductWizard_SidebarConfig_ListWithHeader_Component_Args
'@typescript-eslint/class-name-casing': 'off', // Allow two levels of separation, e. g. ProductWizard_SidebarConfig_ListWithHeader_Component_Args
'@typescript-eslint/no-empty-function': 'off', // Noop is a valid technique.
'@typescript-eslint/no-empty-interface': 'off', // Required for simplified typing of Mirage and Ember Data
'@typescript-eslint/no-non-null-assertion': 'off', // When I do it, I mean it.
'@typescript-eslint/no-unsafe-assignment': 'off', // Reenabled for TS files only
'@typescript-eslint/no-unsafe-call': 'off', // Reenabled for TS files only
'@typescript-eslint/no-unsafe-member-access': 'off', // Reenabled for TS files only
'@typescript-eslint/no-unsafe-return': 'off', // Reenabled for TS files only
'@typescript-eslint/no-unused-expressions': 'off', // Reenabled for non-tests only (Chai needs this disabled)
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-var-requires': 'off', // Reenabled for non-Node files only

// As this rule would freak out on JS files (by design!),
// it has to be enabled only for .ts in the overrides section,
// See https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md#configuring-in-a-mixed-jsts-codebase
'@typescript-eslint/explicit-function-return-type': 'off',

camelcase: 'off', // Have to keep this off for the TS equivalent to take precedence
'no-console': ['error', { allow: ['debug', 'error', 'info', 'warn'] }],
'no-unused-expressions': 'off',
'no-useless-constructor': 'off', // This rule crashes ESLint unless disabled

'node/no-unpublished-require': 'off', // Reenabled for non-Node files only

'prefer-const': 'error', // Only use `let` when you are actually mutating the variable
'prettier/prettier': 'error',
},
overrides: [
// node files
{
files: [
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'index.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**'
],
files: nodeFiles,
parserOptions: {
sourceType: 'script'
sourceType: 'script',
},
env: {
browser: false,
node: true
node: true,
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
rules: {
...require('eslint-plugin-node').configs.recommended.rules, // eslint-disable-line node/no-unpublished-require
// add your custom rules and overrides for node files here
})
}
]
'node/no-unsupported-features/es-syntax': ['error', { version: '>=12.0.0' }],
},
},
{
// browser files, including tests
files: [...browserFiles, ...browserTestFiles],
rules: {
'@typescript-eslint/no-var-requires': 'error', // Reenabled for non-Node files only
'node/no-unpublished-require': 'error', // Reenabled for non-Node files only
},
},
{
/// non-tests
files: [...nodeFiles, ...browserFiles],
rules: {
'@typescript-eslint/no-unused-expressions': 'error', // Reenabled for non-tests only (Chai needs this disabled)
},
},
{
// TS files
files: ['*.ts'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'error', // We want to be strict with types
'@typescript-eslint/no-unsafe-assignment': 'error', // Reenabled for TS files only
'@typescript-eslint/no-unsafe-call': 'error', // Reenabled for TS files only
'@typescript-eslint/no-unsafe-member-access': 'error', // Reenabled for TS files only
'@typescript-eslint/no-unsafe-return': 'error', // Reenabled for TS files only
},
},
],
};
6 changes: 4 additions & 2 deletions .gitignore
Expand Up @@ -9,8 +9,6 @@
/node_modules/

# misc
/.env*
/.pnp*
/.sass-cache
/connect.lock
/coverage/
Expand All @@ -23,3 +21,7 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

# IDE
/.idea/
/.history/
17 changes: 17 additions & 0 deletions .lintstagedrc.js
@@ -0,0 +1,17 @@
'use strict';

module.exports = {
// Run TSC on all the codebase.
// Can't run TSC on individual files because we have two envs: Node and browser,
// and TSC does not support providing a config and a path to a specific file at the same time.
// Thus, two separate configs are used: one for Node, one for browser.
// The function allows running the command globally, rather than once per each staged file.
'{addon,addon-test-support,app,mirage,test-support,tests,types}/**/*.ts': () => 'yarn lint:ts -p tsconfig.json',
'{*,.*,blueprints/*/*,config/**/*,lib/*/index,server/**/*}.{js,ts}': () => 'yarn lint:ts -p tsconfig-node.json',

// Run ESLint, typescript-eslint and Prettier on staged files only
'**/*.{js,ts}': ['yarn lint:eslint --fix'],

// Template lint
'**/*.hbs': ['yarn ember-template-lint'],
};
6 changes: 6 additions & 0 deletions .prettierrc.js
@@ -0,0 +1,6 @@
module.exports = {
arrowParens: 'always', // It's convenient that you don't have to add them by hand when you need to add more args or a type
singleQuote: true, // Enabled to align with EmberJS Prettier config
printWidth: 100, // Per team's agreement
trailingComma: 'es5', // Trailing commas makes editing easier, diffs cleaner. `es5` option aligns with EmberJS Prettier config
};
2 changes: 1 addition & 1 deletion .template-lintrc.js
@@ -1,5 +1,5 @@
'use strict';

module.exports = {
extends: 'octane'
extends: 'recommended'
};

0 comments on commit 997a85b

Please sign in to comment.