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

Fix linting problems #18

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 4 additions & 4 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/**
/*
* @fileoverview Loads the configuration file
* @author Anton Molleda (based on ESLint code: https://github.com/eslint/eslint/blob/master/lib/config/config-file.js)
*/

/* eslint no-use-before-define: 0 */

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
Expand All @@ -20,9 +18,11 @@ import * as requireUncached from 'require-uncached';

const debug = require('debug')('eslint:config-file');

/* eslint-disable no-undef */
interface Config {
sonarConfig?
sonarConfig?: Object
}
/* eslint-enable no-undef */

// ------------------------------------------------------------------------------
// Private
Expand Down
6 changes: 5 additions & 1 deletion src/lib/rule-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* @author Anton Molleda (@molant) based on Nicholas C. Zakas ESLint (https://github.com/eslint/eslint/blob/master/lib/rule-context.js)
*/

import { validate as ruleValidator } from './config/config-rules';
/* eslint-disable no-unused-vars */
Copy link
Contributor Author

@alrra alrra Mar 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@molant We could just drop no-unused-vars and use the noUnusedLocals and noUnusedParameters TypeScript compiler options (as one suggested on the ESLint related issue, but that has its limitations).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored a bit the code and now we don't need to import the types. There are still a couple no-unused-vars out there but not as many as it used to be. I think we should be ok for now but if we see things start getting out of control again we can review this again.

import { Severity, Location } from './types';
import { Sonar } from './sonar';
/* eslint-enable no-unused-vars */

// ------------------------------------------------------------------------------
// Helper functions
Expand Down Expand Up @@ -41,11 +42,14 @@ const findElementLocation = (element: HTMLElement): Location => {

/** Acts as an abstraction layer between rules and the main sonar object. */
export class RuleContext {

/* eslint-disable no-undef */
private id: string
private options: Array<any>
private meta: { any }
private severity: Severity
private sonar: Sonar
/* eslint-enable no-undef */

constructor(ruleId: string, sonar: Sonar, severity: Severity | string, options, meta) {
this.id = ruleId;
Expand Down
8 changes: 5 additions & 3 deletions src/lib/sonar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
// ------------------------------------------------------------------------------

import { EventEmitter2 as EventEmitter } from 'eventemitter2';
import * as _ from 'lodash';

const debug = require('debug')('sonar:engine');

import * as resourceLoader from './util/resource-loader';
import { getSeverity } from './config/config-rules';
import { Plugin, Rule, Collector, Problem, Severity, Location } from './types';
import { Plugin, Rule, Collector, Problem, Severity, Location } from './types'; // eslint-disable-line no-unused-vars
import { RuleContext } from './rule-context';

// import {RuleContext as RuleContext} from './rule-context';
Expand All @@ -25,15 +24,18 @@ import { RuleContext } from './rule-context';

export class Sonar extends EventEmitter {
// TODO: review which ones need to be private or not
/* eslint-disable no-undef */
private plugins: Map<string, Plugin>
private rules: Map<string, Rule>
private collector: Collector
private messages: Array<Problem>
private _sourceHtml: string
/* eslint-enable no-undef */

get sourceHtml() {
return this._sourceHtml;
}

set sourceHtml(sourceHtml) {
this._sourceHtml = sourceHtml;
}
Expand Down Expand Up @@ -110,7 +112,7 @@ export class Sonar extends EventEmitter {
}

/** Reports a message from one of the rules. */
report(ruleId: string, severity: Severity, node, location: Location, message: string, resource: string, meta) {
report(ruleId: string, severity: Severity, node, location: Location, message: string, resource: string) {
const problem = {
column: location.column + 1,
line: location.line,
Expand Down
32 changes: 17 additions & 15 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,58 @@
* @author Anton Molleda (@molant)
*/

/** The builder of a given Rule */
/* eslint-disable no-undef */

/* The builder of a given Rule */
export interface RuleBuilder {
/** Creates an instance of the rule. */
/* Creates an instance of the rule. */
create(config: Object): Rule;
/** The metadata associated to the rule (docs, schema, etc.) */
/* The metadata associated to the rule (docs, schema, etc.) */
meta: {
docs?: any,
fixable?: string,
schema: Array<any>
};
}

/** A rule to be executed */
/* A rule to be executed */
export interface Rule {
[key: string]: (...values: any[]) => void // TODO: this should be of type Listener, find a way to find it
}

/** The builder of a Collector */
/* The builder of a Collector */
export interface CollectorBuilder {
(sonar, options): Collector,
}

/** A collector to be used by Sonar */
/* A collector to be used by Sonar */
export interface Collector {
/** Collects all the information for the given target */
/* Collects all the information for the given target */
collect(target: string): Promise<Array<Object>>;
request;
}

/** A format function that will output the results obtained by Sonar */
/* A format function that will output the results obtained by Sonar */
export interface Formatter {
format(problems: Array<Problem>): void
}

/** A specialized builder of plugins to be used by Sonar */
/* A specialized builder of plugins to be used by Sonar */
export interface PluginBuilder {
/** Creates an instance of the Plugin. */
/* Creates an instance of the Plugin. */
create(config: Object): Plugin;
}

/** A plugin that expands the collector's functionality */
/* A plugin that expands the collector's functionality */
export interface Plugin {
// TBD
any
}

/** A resource required by Sonar: Collector, Formatter, Plugin, Rule, */
/* A resource required by Sonar: Collector, Formatter, Plugin, Rule, */
export type Resource = CollectorBuilder | Formatter | PluginBuilder | RuleBuilder;

/** A problem found by a Rule in Sonar */
/* A problem found by a Rule in Sonar */
export interface Problem {
column: number,
line: number,
Expand All @@ -62,14 +64,14 @@ export interface Problem {
severity: Severity
}

/** The severity configuration of a Rule */
/* The severity configuration of a Rule */
export enum Severity {
off = 0,
warning = 1,
error = 2
}

/** The location of a Problem in the code */
/* The location of a Problem in the code */
export interface Location {
column: number,
line: number
Expand Down