Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

Commit

Permalink
added eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Sep 12, 2017
1 parent 086da67 commit 84e768f
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 80 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/**
test/transpiled/**
22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "airbnb-base",
"root": true,
"rules": {
"no-console": 0,
"indent": [ "error", 4 ],
"no-underscore-dangle": "off"
},
"plugins": [
"jasmine",
"sinon",
"chai"
],
"env": {
"jasmine": true,
"browser": true
},
"globals": {
"testHandler": true,
"sinon": true
}
}
4 changes: 3 additions & 1 deletion .idea/augeas.iml

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

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@
"test": "tests"
},
"scripts": {
"test": "npm run build-tests && wct --plugin sauce",
"test-local": "npm run build-tests && wct -l chrome -p --skip-selenium-install",
"test": "npm run lint && npm run build-tests && wct --plugin sauce",
"test-local": "npm run lint && npm run build-tests && npm run wct",
"build": "rollup -c",
"build-tests": "webpack"
"build-tests": "webpack",
"lint": "eslint src/**/*.js test/**/*.js",
"wct": "wct -l chrome -p --skip-selenium-install"
},
"devDependencies": {
"babel-loader": "^7.1.2",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-es2015": "^6.24.1",
"eslint": "^4.6.1",
"eslint-config-airbnb-base": "^12.0.0",
"eslint-plugin-chai": "0.0.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jasmine": "^2.8.4",
"eslint-plugin-sinon": "^0.2.0",
"rollup": "^0.49.2",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
Expand Down
25 changes: 12 additions & 13 deletions src/elements/ags-view.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {html} from 'lit-html';
import {render} from 'lit-html/lib/lit-extended';
import {PropertyAccessors} from '@polymer/polymer/lib/mixins/property-accessors';
import {ViewTemplates} from '../template-registry';
import { html } from 'lit-html';
import { render } from 'lit-html/lib/lit-extended';
import { PropertyAccessors } from '@polymer/polymer/lib/mixins/property-accessors';
import { ViewTemplates } from '../template-registry';

const defaultWrapper = (view) => html`
const defaultWrapper = view => html`
<style>
:host {
display: block;
Expand All @@ -14,9 +14,8 @@ ${view}`;

const notFoundTemplate = html`<div>Template not found</div>`;

export class AgsView extends PropertyAccessors(HTMLElement) {

constructor(){
export default class AgsView extends PropertyAccessors(HTMLElement) {
constructor() {
super();

this.predicate = null;
Expand All @@ -31,7 +30,7 @@ export class AgsView extends PropertyAccessors(HTMLElement) {
'object',
'predicate',
'templateScope',
'ignoreMissing'
'ignoreMissing',
];
}

Expand All @@ -46,9 +45,9 @@ export class AgsView extends PropertyAccessors(HTMLElement) {
_render() {
let template;

if(this.object) {
if (this.object) {
if (!this.shadowRoot) {
this.attachShadow({mode: 'open'});
this.attachShadow({ mode: 'open' });
}

template = ViewTemplates.getTemplate(this.object, this.predicate, this.templateScope);
Expand All @@ -71,8 +70,8 @@ export class AgsView extends PropertyAccessors(HTMLElement) {

this.dispatchEvent(new CustomEvent('render', {
detail: {
template
}
template,
},
}));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './elements/ags-view';
import {ViewTemplates, FormTemplates} from "./template-registry";
import { ViewTemplates, FormTemplates } from './template-registry';

export {
ViewTemplates,
FormTemplates
}
FormTemplates,
};
2 changes: 1 addition & 1 deletion src/template-registry/TemplateSelector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default class TemplateSelector {
constructor(){
constructor() {
this.name = '';
this._matchers = [];
}
Expand Down
17 changes: 5 additions & 12 deletions src/template-registry/TemplateSelectorBuilder.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
import TemplateSelector from "./TemplateSelector";

export class TemplateSelectorBuilder {
import TemplateSelector from './TemplateSelector';

export default class TemplateSelectorBuilder {
constructor(registry) {
this._registry = registry;
this._selector = new TemplateSelector();
}

value(valueMatcher) {
this._selector._matchers.push((v, p, o) => {
return valueMatcher(v);
});
this._selector._matchers.push(v => valueMatcher(v));

return this;
}

property(propertyMatcher) {
this._selector._matchers.push((v, p, s) => {
return propertyMatcher(p);
});
this._selector._matchers.push((v, p) => propertyMatcher(p));

return this;
}

scope(scopeMatcher) {
this._selector._matchers.push((v, p, s) => {
return scopeMatcher(s);
});
this._selector._matchers.push((v, p, s) => scopeMatcher(s));

return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/template-registry/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TemplateRegistry} from './template-registry';
import TemplateRegistry from './template-registry';

export const ViewTemplates = new TemplateRegistry();
export const FormTemplates = new TemplateRegistry();
20 changes: 8 additions & 12 deletions src/template-registry/template-registry.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {TemplateResult} from 'lit-html';
import {TemplateSelectorBuilder} from "./TemplateSelectorBuilder";

export class TemplateRegistry {
import TemplateSelectorBuilder from './TemplateSelectorBuilder';

export default class TemplateRegistry {
constructor() {
this._templates = [];
}
Expand All @@ -20,28 +18,26 @@ export class TemplateRegistry {
}

getTemplate(value, predicate, scope) {
const selectedTemplate = this._templates.find(template => {
return template.selector.matches(value, predicate, scope);
});
const selectedTemplate = this._templates.find(template =>
template.selector.matches(value, predicate, scope));

return {
render: selectedTemplate.templateFunc,
name: selectedTemplate.name || null
render: selectedTemplate.templateFunc,
name: selectedTemplate.name || null,
};
}

push(selector, templateFuncOrResult, name) {
let templateFunc = templateFuncOrResult;

if(typeof templateFunc !== 'function') {
if (typeof templateFunc !== 'function') {
templateFunc = () => templateFuncOrResult;
}

this._templates.push({
selector,
templateFunc,
name
name,
});
}
}

5 changes: 5 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-unused-expressions": "off"
}
}
32 changes: 17 additions & 15 deletions test/_TestHelpers.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/* eslint-disable */

function setInputValue(input, text) {
input.value = text;
input.dispatchEvent(new Event('input'));
}

(function (Mocha) {
function extendInterfaceWithFixture (interfaceName) {
var originalInterface = Mocha.interfaces[interfaceName];
function extendInterfaceWithFixture(interfaceName) {
var originalInterface = Mocha.interfaces[interfaceName];

Mocha.interfaces[interfaceName] = function (suite) {
originalInterface.apply(this, arguments);
Mocha.interfaces[interfaceName] = function (suite) {
originalInterface.apply(this, arguments);

suite.on('pre-require', function (context, file, mocha) {
context.testHandler = function (target, event, handler) {
suite.on('pre-require', function (context, file, mocha) {
context.testHandler = function (target, event, handler) {

target.addEventListener(event, handler);
target.addEventListener(event, function() {
target.removeEventListener(event, handler);
});
target.addEventListener(event, handler);
target.addEventListener(event, function () {
target.removeEventListener(event, handler);
});
};
});
};
});
};
}
}

Object.keys(Mocha.interfaces).forEach(extendInterfaceWithFixture);
})(this.Mocha);
Object.keys(Mocha.interfaces).forEach(extendInterfaceWithFixture);
})(this.Mocha);
14 changes: 5 additions & 9 deletions test/elements/ags-view.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { html } from 'lit-html';
import '../../src/elements/ags-view';
import {ViewTemplates} from '../../src/template-registry';
import {html} from "lit-html";
import { ViewTemplates } from '../../src/template-registry';

describe('ags-view', () => {

let agsView;
let getTemplate;

Expand All @@ -27,28 +26,25 @@ describe('ags-view', () => {

it('should render found template', (done) => {
getTemplate.returns({
render: (object) => html`<span>${object.value}</span>`
render: object => html`<span>${object.value}</span>`,
});

testHandler(agsView, 'render', () => {
const span = agsView.shadowRoot.querySelector('span');

assert.equal(span.textContent, 'test');
expect(span.textContent).to.equal('test');
done();
});

agsView.object = {
'@id': 'test',
value: 'test'
value: 'test',
};
});

describe('rendering nested templates', () => {

it('should render', () => {

});

});

});
13 changes: 3 additions & 10 deletions test/templates/template-registry.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import {TemplateRegistry} from '../../src/template-registry/template-registry'
import {html, render} from 'lit-html';
import { html, render } from 'lit-html';
import TemplateRegistry from '../../src/template-registry/template-registry';

describe('Template Registry', () => {

let registry;

const matchAllSelector = {
matches: () => true
matches: () => true,
};

beforeEach(() => {
registry = new TemplateRegistry();
});

describe('initially', () => {

it('should be empty', () => {
expect(registry.count).to.be.equal(0);
});

});

describe('when adding selectors', () => {

it('should count them', () => {
// given
registry.when.value(() => true).renders(html``);
Expand All @@ -32,11 +28,9 @@ describe('Template Registry', () => {
// then
expect(registry.count).to.be.equal(3);
});

});

describe('when selecting template', () => {

const templateFunc = () => html``;

it('should return name and template func', () => {
Expand Down Expand Up @@ -78,5 +72,4 @@ describe('Template Registry', () => {
expect(renderTarget.textContent).to.equal('test');
});
});

});

0 comments on commit 84e768f

Please sign in to comment.