Skip to content

Commit

Permalink
refactor: change utils
Browse files Browse the repository at this point in the history
  • Loading branch information
d0whc3r committed Sep 20, 2019
1 parent b8e730b commit 7d30058
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
},
"dependencies": {
"@types/eslint": "^6.1.1",
"@typescript-eslint/parser": "^2.2.0",
"@typescript-eslint/parser": "^2.3.0",
"eslint-utils": "^1.4.2",
"tsutils": "^3.17.1"
},
"peerDependencies": {
"@typescript-eslint/parser": "^2.2.0",
"@typescript-eslint/parser": "^2.3.0",
"eslint": "^6.4.0"
},
"devDependencies": {
"@types/jest": "^24.0.18",
"@typescript-eslint/eslint-plugin": "^2.2.0",
"@typescript-eslint/eslint-plugin": "^2.3.0",
"eslint": "^6.4.0",
"jest": "^24.9.0",
"jest-cli": "^24.9.0",
Expand Down
4 changes: 2 additions & 2 deletions src/rules/decorators-style.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Rule } from 'eslint';
import ts from 'typescript';
import { decoratorName, getDecorator, stencilComponentContext, stencilDecorators } from '../utils';
import { decoratorName, getDecorator, stencilComponentContext, DECORATORS } from '../utils';
import * as os from 'os';

type DecoratorsStyleOptionsEnum = 'inline' | 'multiline' | 'ignore';
Expand Down Expand Up @@ -111,7 +111,7 @@ const rule: Rule.RuleModule = {
return;
}
const decorators: any[] = getDecorator(node);
decorators.filter((dec) => stencilDecorators.includes(decoratorName(dec))).forEach(checkStyle);
decorators.filter((dec) => DECORATORS.includes(decoratorName(dec))).forEach(checkStyle);
}

return {
Expand Down
6 changes: 3 additions & 3 deletions src/rules/own-methods-must-be-private.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Rule } from 'eslint';
import ts from 'typescript';
import { isPrivate, stencilComponentContext, stencilDecorators, stencilLifecycle } from '../utils';
import { isPrivate, stencilComponentContext, DECORATORS, LIFECYCLE_METHODS } from '../utils';

const rule: Rule.RuleModule = {
meta: {
Expand All @@ -26,8 +26,8 @@ const rule: Rule.RuleModule = {
}
const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node);
const stencilDecorator = originalNode.decorators && originalNode.decorators.some(
(dec: any) => stencilDecorators.includes(dec.expression.expression.escapedText));
const stencilCycle = stencilLifecycle.includes(originalNode.name.escapedText);
(dec: any) => DECORATORS.includes(dec.expression.expression.escapedText));
const stencilCycle = LIFECYCLE_METHODS.includes(originalNode.name.escapedText);
if (!stencilDecorator && !stencilCycle && !isPrivate(originalNode)) {
const text = String(originalNode.getFullText());
context.report({
Expand Down
4 changes: 2 additions & 2 deletions src/rules/own-props-must-be-private.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Rule } from 'eslint';
import { isPrivate, stencilComponentContext, stencilDecorators } from '../utils';
import { isPrivate, stencilComponentContext, DECORATORS } from '../utils';

const rule: Rule.RuleModule = {
meta: {
Expand All @@ -25,7 +25,7 @@ const rule: Rule.RuleModule = {
}
const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node);
const stencilDecorator = originalNode.decorators && originalNode.decorators.some(
(dec: any) => stencilDecorators.includes(dec.expression.expression.escapedText));
(dec: any) => DECORATORS.includes(dec.expression.expression.escapedText));
if (!stencilDecorator && !isPrivate(originalNode)) {
const text = String(originalNode.getFullText());
context.report({
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export function getType(node: any) {
return node.typeAnnotation.typeAnnotation.typeName.name;
}

export const stencilDecorators = ['Component', 'Prop', 'State', 'Watch', 'Element', 'Method', 'Event', 'Listen'];
export const DECORATORS = ['Component', 'Prop', 'State', 'Watch', 'Element', 'Method', 'Event', 'Listen'];

export const stencilLifecycle = [
export const LIFECYCLE_METHODS = [
'connectedCallback',
'disconnectedCallback',
'componentWillLoad',
Expand Down

0 comments on commit 7d30058

Please sign in to comment.