Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/master' into feature/update_feat…
Browse files Browse the repository at this point in the history
…ures

# Conflicts:
#	README.md
#	docs/async-methods.md
#	docs/ban-prefix.md
#	docs/class-pattern.md
#	docs/decorators-context.md
#	docs/decorators-style.md
#	docs/element-type.md
#	docs/host-data-deprecated.md
#	docs/methods-must-be-public.md
#	docs/no-unused-watch.md
#	docs/own-methods-must-be-private.md
#	docs/own-props-must-be-private.md
#	docs/prefer-vdom-listener.md
#	docs/props-must-be-public.md
#	docs/props-must-be-readonly.md
#	docs/render-returns-host.md
#	docs/required-jsdoc.md
#	docs/required-prefix.md
#	docs/reserved-member-names.md
#	docs/single-export.md
#	docs/strict-mutable.md
#	package-lock.json
#	package.json
#	src/configs/index.ts
#	src/configs/recommended.ts
#	src/rules/async-methods.ts
#	src/rules/decorators-style.ts
#	src/rules/element-type.ts
#	src/rules/index.ts
#	src/rules/methods-must-be-public.ts
#	src/rules/no-unused-watch.ts
#	src/rules/own-methods-must-be-private.ts
#	src/rules/own-props-must-be-private.ts
#	src/rules/prefer-vdom-listener.ts
#	src/rules/props-must-be-public.ts
#	src/rules/render-returns-host.ts
#	src/rules/required-jsdoc.ts
#	src/rules/required-prefix.ts
#	src/rules/reserved-member-names.ts
#	src/rules/strict-mutable.ts
#	src/utils.ts
#	tests/lib/rules/element-type/element-type.spec.ts
#	tests/lib/rules/element-type/element-type.wrong.tsx
#	tests/lib/rules/strict-mutable/strict-mutable.good.tsx
#	tsconfig.json
  • Loading branch information
d0whc3r committed Nov 5, 2019
2 parents 7344221 + 6717694 commit df29fc7
Show file tree
Hide file tree
Showing 29 changed files with 813 additions and 130 deletions.
19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,38 @@
],
"main": "dist/index.js",
"files": [
"dist"
"dist/index.js"
],
"scripts": {
"build": "tsc -p .",
"build": "tsc -p . && rollup -c",
"test": "jest --coverage",
"version": "npm run build",
"release": "np"
},
"dependencies": {
"@types/eslint": "^6.1.3",
"@typescript-eslint/parser": "^2.5.0",
"eslint-utils": "^1.4.3",
"tsutils": "^3.17.1"
},
"peerDependencies": {
"@typescript-eslint/parser": "^2.5.0",
"eslint": "^6.5.1"
"@typescript-eslint/parser": "^2.4.0",
"@typescript-eslint/eslint-plugin": "^2.4.0",
"eslint-plugin-react": "^7.16.0",
"eslint": "^6.0.0",
"typescript": "^3.5.0"
},
"devDependencies": {
"@types/eslint": "^6.1.3",
"@types/jest": "^24.0.19",
"@typescript-eslint/eslint-plugin": "^2.5.0",
"@typescript-eslint/parser": "^2.5.0",
"eslint": "^6.5.1",
"eslint-plugin-react": "^7.16.0",
"eslint-utils": "^1.4.2",
"jest": "^24.9.0",
"jest-cli": "^24.9.0",
"np": "^5.1.1",
"rollup": "^1.24.0",
"rollup-plugin-node-resolve": "^5.2.0",
"ts-jest": "^24.1.0",
"typescript": "3.6.4"
},
Expand Down
22 changes: 22 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import nodeResolve from 'rollup-plugin-node-resolve';
export default {
input: 'dist/build/index.js',
plugins: [
nodeResolve({
preferBuiltins: true
})
],
treeshake: {
pureExternalModules: true
},
external: [
'eslint',
'typescript',
'tsutils',
'eslint-utils'
],
output: {
file: 'dist/index.js',
format: 'commonjs'
}
};
32 changes: 32 additions & 0 deletions src/configs/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default {
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
'jsx': true
}
},
plugins: [
'@stencil'
],
rules: {
'@stencil/async-methods': 2,
'@stencil/ban-prefix': [2, ['stencil', 'stnl', 'st']],
'@stencil/decorators-context': 2,
'@stencil/element-type': 2,
'@stencil/host-data-deprecated': 2,
'@stencil/methods-must-be-public': 2,
'@stencil/no-unused-watch': 2,
'@stencil/prefer-vdom-listener': 2,
'@stencil/props-must-be-public': 2,
'@stencil/render-returns-host': 2,
'@stencil/reserved-member-names': 2,
'@stencil/single-export': 2,
}
}
]
};
6 changes: 5 additions & 1 deletion src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import base from './base';
import recommended from './recommended';
import strict from './strict';

export default {
recommended
base,
recommended,
strict
};
72 changes: 37 additions & 35 deletions src/configs/recommended.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
export default {
overrides: [
{
parser: '@typescript-eslint/parser',
files: ['*.ts', '*.tsx'],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
'jsx': true
}
},
plugins: [
"react"
],
extends: [
"plugin:@stencil/base",
],
rules: {
'@d0whc3r/stencil/async-methods': 'error',
'@d0whc3r/stencil/ban-prefix': ['error', ['stencil', 'stnl', 'st']],
// '@d0whc3r/stencil/component-order': [
// 'error', {
// order: [
// 'own-prop',
// 'element',
// 'state',
// 'watched-state',
// 'prop',
// 'watched-prop',
// 'event',
// 'lifecycle',
// 'listen',
// 'method',
// 'own-method',
// 'render'
// ],
// followingWatch: true,
// alphabetical: true
// }],
'@d0whc3r/stencil/decorators-context': 'error',
'@d0whc3r/stencil/decorators-style': [
'error', {
Expand All @@ -57,10 +33,36 @@ export default {
'@d0whc3r/stencil/required-jsdoc': 'error',
'@d0whc3r/stencil/reserved-member-names': 'error',
'@d0whc3r/stencil/single-export': 'error',
'@d0whc3r/stencil/strict-mutable': 'error'
},
plugins: [
'@d0whc3r/stencil'
]
'@d0whc3r/stencil/strict-mutable': 'error,
"react/jsx-no-bind": [1, {
"ignoreRefs": true
}]
}
};

/*
rules: {
'@stencil/strict-boolean-conditions': 2,
'@stencil/ban-exported-const-enums': 2,
'@stencil/ban-side-effects': 2,
'@stencil/strict-mutable': 2,
'@stencil/decorators-style': [
'error', {
prop: 'inline',
state: 'inline',
element: 'inline',
event: 'inline',
method: 'multiline',
watch: 'multiline',
listen: 'multiline'
}
],
'@stencil/own-methods-must-be-private': 1,
'@stencil/own-props-must-be-private': 1,
'@stencil/dependency-suggestions': 1,
'@stencil/required-jsdoc': 1,
"react/jsx-no-bind": [1, {
"ignoreRefs": true
}]
}
*/
58 changes: 58 additions & 0 deletions src/configs/strict.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export default {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@stencil/recommended",
],
rules: {
// Resets
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/ban-ts-ignore": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-unused-vars": 0,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/no-explicit-any": 0,
"no-constant-condition": 0,


// Best practices
"no-shadow": 2,
"require-atomic-updates": 2,
"no-var": 2,
"prefer-object-spread": 2,
"no-nested-ternary": 2,
"no-duplicate-imports": 2,

// General formatting
"indent": [2, 2],
"no-trailing-spaces": 2,
"curly": [2, "all"],
"comma-spacing": 2,
"comma-style": 2,
"computed-property-spacing": 2,
"comma-dangle": [2, "always-multiline"],
"func-style": [2, "expression", { "allowArrowFunctions": true }],
"multiline-ternary": [2, "always-multiline"],
"operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }],
"linebreak-style": 2,
"space-in-parens": 2,
"@typescript-eslint/semi": 2,
"@typescript-eslint/brace-style": 2,
"@typescript-eslint/func-call-spacing": 2,

// JSX formatting
"react/jsx-closing-tag-location": 2,
"react/jsx-curly-newline": [2, "never"],
"react/jsx-closing-bracket-location": 2,
"react/jsx-curly-spacing": [2, {"when": "never", "children": true}],
"react/jsx-boolean-value": [2, "never"],
"react/jsx-child-element-spacing": 2,
"react/jsx-indent-props": [2, "first"],
"react/jsx-props-no-multi-spaces": 2,
"react/jsx-equals-spacing": [2, "never"],
}
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import rules from './rules';
import configs from './configs';

export = {
export {
rules,
configs
};
4 changes: 2 additions & 2 deletions src/rules/async-methods.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Rule } from 'eslint';
import ts from 'typescript';
import { stencilComponentContext } from '../utils';
import * as tsutils from 'tsutils';
import { isThenableType } from 'tsutils';

const rule: Rule.RuleModule = {
meta: {
Expand Down Expand Up @@ -30,7 +30,7 @@ const rule: Rule.RuleModule = {
const method = parserServices.esTreeNodeToTSNodeMap.get(node);
const signature = typeChecker.getSignatureFromDeclaration(method);
const returnType = typeChecker.getReturnTypeOfSignature(signature!);
if (!tsutils.isThenableType(typeChecker, method, returnType)) {
if (!isThenableType(typeChecker, method, returnType)) {
const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node) as ts.Node;
const text = String(originalNode.getFullText());
context.report({
Expand Down
26 changes: 26 additions & 0 deletions src/rules/ban-exported-const-enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Rule } from 'eslint';

const rule: Rule.RuleModule = {
meta: {
docs: {
description: 'This rule catches exports of const enums',
category: 'Possible Errors',
recommended: true
},
schema: [],
type: 'problem'
},

create(context): Rule.RuleListener {
return {
'ExportNamedDeclaration > TSEnumDeclaration[const]': (node: any) => {
context.report({
node: node,
message: `Exported const enums are not allowed`
});
}
};
}
};

export default rule;
65 changes: 65 additions & 0 deletions src/rules/ban-side-effects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Rule } from 'eslint';

const rule: Rule.RuleModule = {
meta: {
docs: {
description: 'This rule catches function calls at the top level',
category: 'Possible Errors',
recommended: false
},
schema: [
{
type: 'array',
items: {
type: 'string'
},
minLength: 0,
additionalProperties: false
}
],
type: 'suggestion'
},

create(context): Rule.RuleListener {
const shouldSkip = /\b(spec|e2e|test)\./.test(context.getFilename());
const skipFunctions = context.options[0] || DEFAULTS;
if (shouldSkip) {
return {};
}
return {
'CallExpression': (node: any) => {
if (skipFunctions.includes(node.callee.name)) {
return;
}
if (!isInScope(node)) {
context.report({
node: node,
message: `Call expressions at the top-level should be avoided.`
});
}
}
};
}
};

const isInScope = (n: any): boolean => {
const type = n.type;
if (
type === 'ArrowFunctionExpression' ||
type === 'FunctionDeclaration' ||
type === 'ClassDeclaration' ||
type === 'ExportNamedDeclaration'
) {
return true;
}
n = n.parent;
if (n) {
return isInScope(n);
}
return false;
}

const DEFAULTS = ['describe', 'test', 'bind'];

export default rule;

2 changes: 1 addition & 1 deletion src/rules/decorators-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const rule: Rule.RuleModule = {
return {
...stencil.rules,
'ClassProperty': getStyle,
'MethodDefinition': getStyle
'MethodDefinition[kind=method]': getStyle
};
}
};
Expand Down
Loading

0 comments on commit df29fc7

Please sign in to comment.