Skip to content

Commit

Permalink
chore(dev-infra): configure eslint rule `padding-line-between-stateme…
Browse files Browse the repository at this point in the history
…nts` (#1676)
  • Loading branch information
ahnpnl committed May 24, 2020
1 parent 8f2b2dc commit be32e7b
Show file tree
Hide file tree
Showing 26 changed files with 126 additions and 71 deletions.
146 changes: 75 additions & 71 deletions .eslintrc.js
Expand Up @@ -24,14 +24,36 @@ module.exports = {
},
plugins: ['@typescript-eslint', 'jest', 'jsdoc'],
rules: {
'prettier/prettier': 'error',
'no-unused-vars': 'off', // let typescript-eslint handle this
'no-console': 'error',
'linebreak-style': 'off',
'arrow-body-style': 'warn',
'arrow-parens': ['off', 'always'],
'brace-style': ['off', 'off'],
camelcase: 'warn',
'class-methods-use-this': 'warn',
'comma-dangle': 'off',
complexity: 'off',
'constructor-super': 'error',
curly: ['warn', 'multi-line'],
'default-case': 'error',
'dot-notation': 'error',
'eol-last': 'off',
eqeqeq: ['error', 'smart'],
'for-direction': ['error'],
'getter-return': 'warn',
'guard-for-in': 'error',
'id-match': 'error',
'jsdoc/check-alignment': 'error',
'jsdoc/check-indentation': 'error',
'jsdoc/newline-after-description': 'warn',
'linebreak-style': 'off',
'max-classes-per-file': 'off',
'max-len': 'off',
'new-parens': 'off',
'newline-per-chained-call': 'off',
'no-bitwise': 'off',
'no-caller': 'error',
'no-duplicate-imports': 'error',
'no-eval': 'error',
'no-console': 'error',
'no-async-promise-executor': ['error'],
'no-case-declarations': ['error'],
'no-class-assign': ['error'],
Expand Down Expand Up @@ -61,40 +83,79 @@ module.exports = {
'no-func-assign': ['error'],
'no-global-assign': ['error'],
'no-inner-declarations': ['error'],
'no-invalid-this': 'off',
'no-invalid-regexp': ['error'],
'no-irregular-whitespace': 'off',
'no-misleading-character-class': ['error'],
'no-mixed-spaces-and-tabs': ['error'],
'no-multiple-empty-lines': 'off',
'no-new-symbol': ['error'],
'no-new-wrappers': 'error',
'no-obj-calls': ['error'],
'no-octal': ['error'],
'no-prototype-builtins': ['error'],
'no-redeclare': 'warn',
'no-regex-spaces': ['error'],
'no-return-await': 'error',
'no-self-assign': ['error'],
'no-shadow': [
'off',
{
hoist: 'all',
},
],
'no-shadow-restricted-names': ['error'],
'no-sparse-arrays': ['error'],
'no-template-curly-in-string': 'error',
'no-this-before-super': ['error'],
'no-throw-literal': 'error',
'no-trailing-spaces': 'off',
'no-undef-init': 'error',
'no-underscore-dangle': 'off',
'no-unused-expressions': 'error',
'no-undef': ['error'],
'no-unexpected-multiline': ['error'],
'no-unreachable': ['error'],
'no-unsafe-finally': 'error',
'no-unsafe-negation': ['error'],
'no-unused-labels': 'error',
'no-unused-vars': 'off', // let typescript-eslint handle this
'no-useless-catch': ['error'],
'no-useless-escape': 'warn',
'no-var': 'error',
'no-with': ['error'],
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'padding-line-between-statements': [
"error",
{ blankLine: "always", prev: "*", next: "return" }
],
'prefer-const': 'error',
'prefer-object-spread': 'error',
'prefer-template': 'error',
'prettier/prettier': 'error',
'quote-props': 'off',
radix: 'error',
'require-yield': ['error'],
'space-before-function-paren': 'off',
'space-in-parens': ['off', 'never'],
'spaced-comment': [
'warn',
'always',
{
markers: ['/'],
},
],
'use-isnan': 'error',
'valid-typeof': 'off',
'@typescript-eslint/no-unused-vars': ["error", { "argsIgnorePattern": "^_" }],
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': [
'warn',
{
default: 'array',
},
],
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ban-types': [
'error',
{
Expand All @@ -120,12 +181,9 @@ module.exports = {
},
},
],
'@typescript-eslint/prefer-regexp-exec': 'warn',
'@typescript-eslint/prefer-string-starts-ends-with': 'warn',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/prefer-includes': 'warn',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
Expand All @@ -146,11 +204,9 @@ module.exports = {
},
},
],
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/no-unused-vars': ["error", { "argsIgnorePattern": "^_" }],
'@typescript-eslint/no-empty-function': ['error', { 'allow': ['arrowFunctions']}],
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
Expand All @@ -163,13 +219,18 @@ module.exports = {
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/prefer-includes': 'warn',
'@typescript-eslint/prefer-regexp-exec': 'warn',
'@typescript-eslint/prefer-string-starts-ends-with': 'warn',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/triple-slash-reference': [
'error',
{
Expand All @@ -179,65 +240,8 @@ module.exports = {
},
],
'@typescript-eslint/type-annotation-spacing': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'arrow-body-style': 'warn',
'arrow-parens': ['off', 'always'],
'brace-style': ['off', 'off'],
camelcase: 'warn',
'class-methods-use-this': 'warn',
complexity: 'off',
curly: ['warn', 'multi-line'],
'default-case': 'error',
'dot-notation': 'error',
'eol-last': 'off',
eqeqeq: ['error', 'smart'],
'guard-for-in': 'error',
'id-match': 'error',
'jsdoc/check-alignment': 'error',
'jsdoc/check-indentation': 'error',
'jsdoc/newline-after-description': 'warn',
'max-classes-per-file': 'off',
'max-len': 'off',
'new-parens': 'off',
'newline-per-chained-call': 'off',
'no-bitwise': 'off',
'no-caller': 'error',
'no-duplicate-imports': 'error',
'no-eval': 'error',
'no-invalid-this': 'off',
'no-multiple-empty-lines': 'off',
'no-new-wrappers': 'error',
'no-return-await': 'error',
'no-shadow': [
'off',
{
hoist: 'all',
},
],
'no-template-curly-in-string': 'error',
'no-throw-literal': 'error',
'no-trailing-spaces': 'off',
'no-undef-init': 'error',
'no-underscore-dangle': 'off',
'no-unused-expressions': 'error',
'no-var': 'error',
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'prefer-const': 'warn',
'prefer-object-spread': 'error',
'prefer-template': 'error',
'quote-props': 'off',
radix: 'error',
'space-before-function-paren': 'off',
'space-in-parens': ['off', 'never'],
'spaced-comment': [
'warn',
'always',
{
markers: ['/'],
},
],
},
settings: {},
}
1 change: 1 addition & 0 deletions e2e/__helpers__/test-case/run-descriptor.ts
Expand Up @@ -101,6 +101,7 @@ function createIteratorContext(templateName: string, expectedStatus?: number): R
if (status == null) {
return 'run'
}

return status === 0 ? 'pass' : 'fail'
}

Expand Down
1 change: 1 addition & 0 deletions e2e/__helpers__/test-case/run-result.ts
Expand Up @@ -36,6 +36,7 @@ export default class RunResult {
const lines = this.logFileContent.split(/\n/g)
// remove last, empty line
lines.pop()

return lines.map(s => JSON.parse(s))
}

Expand Down
4 changes: 4 additions & 0 deletions e2e/__helpers__/test-case/runtime.ts
Expand Up @@ -49,6 +49,7 @@ function hooksSourceWith(vars: Record<string, any>): string {
if (!__hooksSource) {
__hooksSource = readFileSync(join(__dirname, '__hooks-source__.js.hbs'), 'utf8')
}

// eslint-disable-next-line no-useless-escape
return __hooksSource.replace(/\{\{([^\}]+)\}\}/g, (_, key) => JSON.stringify(vars[key]))
}
Expand Down Expand Up @@ -253,6 +254,7 @@ export function prepareTest(name: string, template: string, options: RunTestOpti
segments.pop()
}
snapshotDirs[segments.join(sep)] = 0

return false
} else if (relPath === 'jest.config.js') {
// extend base if it's a function
Expand All @@ -263,8 +265,10 @@ export function prepareTest(name: string, template: string, options: RunTestOpti
const mod = require(src)
if (typeof mod === 'function') {
writeFileSync(dest, `module.exports = ${JSON.stringify(mod(baseConfig, configUtils))}`)

return false
}

return true
} else {
return true
Expand Down
3 changes: 3 additions & 0 deletions e2e/__helpers__/test-case/utils.ts
Expand Up @@ -12,6 +12,7 @@ export function templateNameForPath(path: string): string {
if (existsSync(e2eFile)) {
return require(e2eFile).template || 'default'
}

return 'default'
}

Expand All @@ -21,6 +22,7 @@ const FAIL_MARKS = ['×', '✕']
const normalizeTestMark = (mark: string): string => {
if (PASS_MARKS.includes(mark)) return PASS_MARKS[0]
if (FAIL_MARKS.includes(mark)) return FAIL_MARKS[0]

return '?'
}

Expand All @@ -41,6 +43,7 @@ export function normalizeJestOutput(output: string): string {
if (process.platform === 'win32') {
out = out.replace(/\\/g, '/')
}

return out
}

Expand Down
3 changes: 3 additions & 0 deletions scripts/e2e.js
Expand Up @@ -31,6 +31,7 @@ function getDirectories(rootDir) {
function sha1(...data) {
const hash = createHash('sha1')
data.forEach((item) => hash.update(item))

return hash.digest('hex').toString()
}

Expand Down Expand Up @@ -105,6 +106,7 @@ function setupE2e() {
// no package-lock.json => this template doesn't provide any package-set
if (!fs.existsSync(pkgLockFile)) {
log(` [template: ${name}]`, 'not a package-set template, nothing to do')

return
}

Expand All @@ -119,6 +121,7 @@ function setupE2e() {
if (bundleOk && packagesOk) {
log(` [template: ${name}]`, 'bundle and packages unchanged, nothing to do')
logPackageVersions()

return
}
}
Expand Down
1 change: 1 addition & 0 deletions scripts/lib/bundle.js
Expand Up @@ -42,6 +42,7 @@ function computePackageDigest(noWriteFile = false) {
if (!noWriteFile) {
writeFileSync(pkgDigestFile, digest, 'utf8')
}

return digest
}

Expand Down
1 change: 1 addition & 0 deletions scripts/lib/npm.js
Expand Up @@ -22,6 +22,7 @@ function directDepsPkg(dir) {
if (res[key]) return
res[key] = require(join(dir, 'node_modules', key, 'package.json'))
})

return res
}

Expand Down
1 change: 1 addition & 0 deletions scripts/lib/spawn-sync.js
Expand Up @@ -15,6 +15,7 @@ const spawnSync = (...args) => {
msgs.push('unknown error')
throw new Error(msgs.find((s) => s))
}

return res
}

Expand Down
1 change: 1 addition & 0 deletions src/__helpers__/fakers.ts
Expand Up @@ -37,6 +37,7 @@ export function getJestConfig<T extends Config.ProjectConfig>(
if (tsJestOptions) {
res.globals['ts-jest'] = tsJestOptions
}

return res
}

Expand Down
1 change: 1 addition & 0 deletions src/__helpers__/mocks.ts
Expand Up @@ -24,6 +24,7 @@ export const mockObject = <T, M>(obj: T, newProps: M): T & M & { mockRestore: ()
Object.keys(backup).forEach((key) => {
Object.defineProperty(obj, key, backup[key])
})

return obj
},
configurable: true,
Expand Down
1 change: 1 addition & 0 deletions src/__helpers__/processed-source.ts
Expand Up @@ -29,6 +29,7 @@ export default class ProcessedSource {
get normalizedOutputSourceMaps(): RawSourceMap | undefined {
const maps = this.outputSourceMaps
if (maps) return this.sourceMapsNormalizer(maps)

return undefined
}
get sourceMapsNormalizer() {
Expand Down

0 comments on commit be32e7b

Please sign in to comment.