Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use eslint-config-metarhia and fix linting issues #126

Merged
merged 1 commit into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 1 addition & 171 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,171 +1 @@
env:
es6: true
node: true
extends: 'eslint:recommended'
rules:
indent:
- error
- 2
- SwitchCase: 1
VariableDeclarator:
var: 2
let: 2
const: 3
MemberExpression: 1
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- always
eqeqeq:
- error
- always
no-loop-func:
- error
strict:
- error
- global
block-spacing:
- error
- always
brace-style:
- error
- 1tbs
- allowSingleLine: true
camelcase:
- error
comma-style:
- error
- last
comma-spacing:
- error
- before: false
after: true
eol-last:
- error
func-call-spacing:
- error
- never
key-spacing:
- error
- beforeColon: false
afterColon: true
mode: minimum
keyword-spacing:
- error
- before: true
after: true
overrides:
function:
after: false
max-len:
- error
- code: 80
ignoreUrls: true
max-nested-callbacks:
- error
- max: 7
new-cap:
- error
- newIsCap: true
capIsNew: true
properties: true
new-parens:
- error
no-lonely-if:
- error
no-trailing-spaces:
- error
no-unneeded-ternary:
- error
no-whitespace-before-property:
- error
object-curly-spacing:
- error
- always
operator-assignment:
- error
- always
operator-linebreak:
- error
- after
semi-spacing:
- error
- before: false
after: true
space-before-blocks:
- error
- always
space-before-function-paren:
- error
- never
space-in-parens:
- error
- never
space-infix-ops:
- error
space-unary-ops:
- error
- words: true
nonwords: false
overrides:
typeof: false
no-unreachable:
- error
no-global-assign:
- error
no-self-compare:
- error
no-unmodified-loop-condition:
- error
no-constant-condition:
- error
- checkLoops: false
no-console:
- off
no-useless-concat:
- error
no-useless-escape:
- error
no-shadow-restricted-names:
- error
no-use-before-define:
- error
- functions: false
arrow-body-style:
- error
- as-needed
arrow-spacing:
- error
no-confusing-arrow:
- error
- allowParens: true
no-useless-computed-key:
- error
no-useless-rename:
- error
no-var:
- error
object-shorthand:
- error
- always
prefer-arrow-callback:
- error
prefer-const:
- error
prefer-numeric-literals:
- error
prefer-rest-params:
- error
prefer-spread:
- error
rest-spread-spacing:
- error
- never
template-curly-spacing:
- error
- never
extends: 'metarhia'
9 changes: 2 additions & 7 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ const path = require('path');

const common = require('metarhia-common');

let metaschema;
try {
metaschema = require('metaschema');
} catch (e) {
metaschema = require('..');
}
const metaschema = require('..');

const cwd = process.cwd();
const apiFile = path.resolve(cwd, process.argv[2]);
Expand All @@ -23,7 +18,7 @@ try {
const md = metaschema.generateMd(inventory);
const mdFile = common.removeExt(apiFile) + '.md';

fs.writeFile(mdFile, md, (err) => {
fs.writeFile(mdFile, md, err => {
if (err) console.log('Cant save output: ' + mdFile);
else console.log('Generated API docs: ' + mdFile);
});
Expand Down
6 changes: 3 additions & 3 deletions lib/decorators.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = {
Local: def => new Local(def),
History: def => new History(def),
View: def => new View(def),
Memory: def => new Memory(def)
Memory: def => new Memory(def),
},
attribute: {
// Field decorators
Expand All @@ -97,6 +97,6 @@ module.exports = {
Index: (...fields) => new Index(fields),
Unique: (...fields) => new Unique(fields),
// Validation function decorator
Validate: fn => Object.setPrototypeOf(fn, Validate)
}
Validate: fn => Object.setPrototypeOf(fn, Validate),
},
};
9 changes: 4 additions & 5 deletions lib/generator.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const generateMd = (
// Generate md from interfaces inventory
inventory // hash of hash of record, { method, title, parameters }
// Returns: string, md document
) => {
// Generate md from interfaces inventory
// inventory - hash of hash of record, { method, title, parameters }
// Returns: string, md document
const generateMd = inventory => {
const buf = [];
for (const name in inventory) {
const methods = inventory[name];
Expand Down
24 changes: 11 additions & 13 deletions lib/introspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ const parseLines = (
}
};

const parseSignature = (
// Parse function signature
fn // function, method
// Returns: { title, description, parameters, comments }
) => {
// Parse function signature
// fn - function, method
// Returns: { title, description, parameters, comments }
const parseSignature = fn => {
const signature = {
title: '', description: '',
parameters: [], comments: []
parameters: [], comments: [],
};
let s = fn.toString();
let pos = FUNC_TERMS.map(indexing(s))
Expand All @@ -71,11 +70,10 @@ const parseSignature = (
return signature;
};

const introspect = (
// Introspect interface
namespace // hash of interfaces
// Returns: hash of hash of record, { method, title, parameters }
) => {
// Introspect interface
// namespace - hash of interfaces
// Returns: hash of hash of record, { method, title, parameters }
const introspect = namespace => {
const inventory = {};
for (const name in namespace) {
const iface = namespace[name];
Expand All @@ -85,7 +83,7 @@ const introspect = (
const fn = iface[method];
const signature = parseSignature(fn);
methods[method] = Object.assign({
method: name + '.' + method
method: name + '.' + method,
}, signature);
}
}
Expand All @@ -94,5 +92,5 @@ const introspect = (

module.exports = {
introspect,
parseSignature
parseSignature,
};
38 changes: 16 additions & 22 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ const categories = new Map();
const structs = {};

const ValidationErrorSerializer = {
linkToLog: (error) =>
'Forbidden reference to a \'Log\' category ' +
`from ${error.source}.${error.property}`,
illegalLinkToLocal: (error) =>
`Illegal reference to a 'Local' category '${error.info.destination}' ` +
`from ${error.source}.${error.property}`,
unresolvedDomain: (error) =>
`Reference to an unresolved domain '${error.info.domain}' ` +
`from ${error.source}.${error.property}`,
unresolvedCategory: (error) =>
`Reference to an unresolved category '${error.info.category}' ` +
linkToLog: error => 'Forbidden reference to a \'Log\' category ' +
`from ${error.source}.${error.property}`,
illegalLinkToLocal: error => 'Illegal reference to a \'Local\' category' +
` '${error.info.destination}' from ${error.source}.${error.property}`,
unresolvedDomain: error => 'Reference to an unresolved domain' +
` '${error.info.domain}' from ${error.source}.${error.property}`,
unresolvedCategory: error => 'Reference to an unresolved category' +
` '${error.info.category}' from ${error.source}.${error.property}`,
};

class ValidationError extends Error {
Expand Down Expand Up @@ -109,7 +105,7 @@ const processSchema = (
// as Local
// category - object
// Returns: string
const getCategoryType = (category) => {
const getCategoryType = category => {
const type = category.constructor.name;
return type === 'Object' ? 'Local' : type;
};
Expand Down Expand Up @@ -147,10 +143,9 @@ const verifyLink = (
return null;
};

const linkSchemas = (
// Crosslink loaded schema
schemas // object, schema collection
) => {
// Crosslink loaded schema
// schemas - object, schema collection
const linkSchemas = schemas => {
const errors = [];
for (const schemaName in schemas) {
const schema = schemas[schemaName];
Expand Down Expand Up @@ -273,11 +268,10 @@ const factorify = (
return factory;
};

const build = (
// Build schemas list (directory)
schemas // object, key: schema
// Returns: function
) => {
// Build schemas list (directory)
// schemas - object, key: schema
// Returns: function
const build = schemas => {
const factories = {};
for (const name in schemas) {
const definition = schemas[name];
Expand Down Expand Up @@ -311,7 +305,7 @@ const load = (
processSchema(file, schema, schemas);
callback(null);
});
}, (err) => {
}, err => {
if (err) {
callback(err);
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ const ALL_TYPES = merge(SCALAR_TYPES, OBJECT_TYPES);
module.exports = {
SCALAR_TYPES,
OBJECT_TYPES,
ALL_TYPES
ALL_TYPES,
};
Loading