Skip to content

Commit

Permalink
Merge pull request #371 from textlint/refator-kernel-interface
Browse files Browse the repository at this point in the history
refactor(kernel): export named export instead of wildcard export
  • Loading branch information
azu committed Dec 13, 2017
2 parents 8fdc29e + b921d4a commit 442c297
Show file tree
Hide file tree
Showing 34 changed files with 228 additions and 229 deletions.
1 change: 1 addition & 0 deletions .prettierignore
@@ -1,2 +1,3 @@
out/
lib/
node_modules/
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -8,6 +8,7 @@
"test/integration-test"
],
"scripts": {
"clean": "lerna run clean",
"publish": "lerna publish --conventional-commits",
"publish:beta": "lerna publish --conventional-commits --npm-tag=next",
"bootstrap": "lerna bootstrap",
Expand Down
6 changes: 3 additions & 3 deletions packages/@textlint/kernel/src/core/rule-error.ts
@@ -1,20 +1,20 @@
// LICENSE : MIT
"use strict";
import { TextLintFixCommand } from "../textlint-kernel-interface";
import { TextlintFixCommand } from "../textlint-kernel-interface";

export interface RuleErrorPadding {
line?: number;
column?: number;
index?: number;
fix?: TextLintFixCommand;
fix?: TextlintFixCommand;
}

export default class RuleError {
public message: string;
private line?: number;
private column?: number;
private index?: number;
private fix?: TextLintFixCommand;
private fix?: TextlintFixCommand;

/**
* RuleError is like Error object.
Expand Down
6 changes: 3 additions & 3 deletions packages/@textlint/kernel/src/fixer/fixer-processor.ts
Expand Up @@ -11,7 +11,7 @@ import {
TextlintFixResult,
TextlintKernelConstructorOptions,
TextlintKernelFilterRule,
TextlintKernelProcessor,
TextlintPluginProcessor,
TextlintKernelRule,
TextlintMessage
} from "../textlint-kernel-interface";
Expand All @@ -26,14 +26,14 @@ export interface FixerProcessorProcessArgs {
}

export default class FixerProcessor {
private processor: TextlintKernelProcessor;
private processor: TextlintPluginProcessor;
private messageProcessManager: MessageProcessManager;

/**
* @param {Processor} processor
* @param {MessageProcessManager} messageProcessManager
*/
constructor(processor: TextlintKernelProcessor, messageProcessManager: MessageProcessManager) {
constructor(processor: TextlintPluginProcessor, messageProcessManager: MessageProcessManager) {
this.processor = processor;
this.messageProcessManager = messageProcessManager;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@textlint/kernel/src/fixer/source-code-fixer.ts
@@ -1,4 +1,4 @@
import { TextLintFixCommand, TextlintMessage } from "../textlint-kernel-interface";
import { TextlintFixCommand, TextlintMessage } from "../textlint-kernel-interface";

const debug = require("debug")("textlint:source-code-fixer");
import SourceCode from "../core/source-code";
Expand Down Expand Up @@ -27,7 +27,7 @@ function clone(object: any) {
}

export interface TextLintMessageFixable extends TextlintMessage {
fix: TextLintFixCommand;
fix: TextlintFixCommand;
}

/**
Expand Down
19 changes: 16 additions & 3 deletions packages/@textlint/kernel/src/index.ts
@@ -1,6 +1,19 @@
// Kernel
export { TextlintKernel } from "./textlint-kernel";
// Types
import * as TextlintTypes from "./textlint-kernel-interface";

export { TextlintTypes };
export {
TextlintResult,
TextlintFixResult,
TextlintFixCommand,
TextlintMessage,
// Kernel rule/filter/plugin
TextlintKernelRule,
TextlintKernelFilterRule,
TextlintKernelPlugin,
// TODO: textlint rule interface
// TODO: textlint filter rule interface
// textlint plugin interface
TextlintPluginCreator,
TextlintPluginProcessor,
TextlintPluginProcessorConstructor
} from "./textlint-kernel-interface";
6 changes: 3 additions & 3 deletions packages/@textlint/kernel/src/linter/linter-processor.ts
Expand Up @@ -6,7 +6,7 @@ import TaskRunner from "../task/task-runner";
import {
TextlintKernelConstructorOptions,
TextlintKernelFilterRule,
TextlintKernelProcessor,
TextlintPluginProcessor,
TextlintKernelRule
} from "../textlint-kernel-interface";
import MessageProcessManager from "../messages/MessageProcessManager";
Expand All @@ -21,14 +21,14 @@ export interface LinterProcessorArgs {
}

export default class LinterProcessor {
private processor: TextlintKernelProcessor;
private processor: TextlintPluginProcessor;
private messageProcessManager: MessageProcessManager;

/**
* @param {Processor} processor
* @param {MessageProcessManager} messageProcessManager
*/
constructor(processor: TextlintKernelProcessor, messageProcessManager: MessageProcessManager) {
constructor(processor: TextlintPluginProcessor, messageProcessManager: MessageProcessManager) {
this.processor = processor;
this.messageProcessManager = messageProcessManager;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@textlint/kernel/src/task/textlint-core-task.ts
Expand Up @@ -13,7 +13,7 @@ import { EventEmitter } from "events";
import * as assert from "assert";
import SourceCode from "../core/source-code";
import { TxtNode } from "@textlint/ast-node-types";
import { TextLintFixCommand, TextlintRuleOptions } from "../textlint-kernel-interface";
import { TextlintFixCommand, TextlintRuleOptions } from "../textlint-kernel-interface";
import { default as RuleContext, RuleReportedObject } from "../core/rule-context";
import { RuleCreatorReporter } from "../core/rule-creator-helper";
import FilterRuleContext from "../core/filter-rule-context";
Expand Down Expand Up @@ -76,7 +76,7 @@ export interface LintReportedMessage {
line: number; // start with 1(1-based line number)
column: number; // start with 1(1-based column number)
severity: number; // it's for compatible ESLint formatter
fix?: TextLintFixCommand;
fix?: TextlintFixCommand;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/@textlint/kernel/src/textlint-kernel-interface.ts
Expand Up @@ -21,7 +21,7 @@ export interface TextlintKernelConstructorOptions {
}

// config
export interface TextlintConfig {
export interface TextlintConfigObject {
// rule directories path
rulePaths?: string[];
// filter by file extensions
Expand Down Expand Up @@ -50,15 +50,15 @@ export interface TextlintConfig {
}

// Plugin
export interface TextlintKernelProcessorConstructor extends Function {
export interface TextlintPluginProcessorConstructor extends Function {
// TODO: support plugin config
// https://github.com/textlint/textlint/issues/296
new (options?: TextlintPluginOptions | boolean): TextlintKernelProcessor;
new (options?: TextlintPluginOptions | boolean): TextlintPluginProcessor;

availableExtensions(): Array<string>;
}

export declare class TextlintKernelProcessor {
export declare class TextlintPluginProcessor {
constructor(options?: TextlintPluginOptions | boolean);

static availableExtensions(): Array<string>;
Expand All @@ -73,7 +73,7 @@ export declare class TextlintKernelProcessor {

// textlint plugin module should export this interface
export interface TextlintPluginCreator {
Processor: TextlintKernelProcessorConstructor;
Processor: TextlintPluginProcessorConstructor;
}

export interface TextlintKernelPlugin {
Expand Down Expand Up @@ -125,7 +125,7 @@ export interface TextlintKernelOptions {
}

// "range" is replaced by "text"
export class TextLintFixCommand {
export class TextlintFixCommand {
text: string;
range: [number, number];
isAbsolute: boolean;
Expand All @@ -141,7 +141,7 @@ export class TextlintMessage {
// optional data
data?: any;
// FixCommand
fix?: TextLintFixCommand;
fix?: TextlintFixCommand;
// location info
// Text -> AST TxtNode(0-based columns) -> textlint -> TextlintMessage(**1-based columns**)
line: number; // start with 1
Expand Down
10 changes: 5 additions & 5 deletions packages/@textlint/kernel/src/textlint-kernel.ts
Expand Up @@ -17,8 +17,8 @@ import {
TextlintKernelConstructorOptions,
TextlintKernelOptions,
TextlintKernelPlugin,
TextlintKernelProcessor,
TextlintKernelProcessorConstructor,
TextlintPluginProcessor,
TextlintPluginProcessorConstructor,
TextlintResult
} from "./textlint-kernel-interface";

Expand All @@ -40,7 +40,7 @@ function findPluginWithExt(plugins: TextlintKernelPlugin[] = [], ext: string) {
const matchPlugins = availablePlugins.filter(kernelPlugin => {
const plugin = kernelPlugin.plugin;
// static availableExtensions() method
const textlintKernelProcessor: TextlintKernelProcessorConstructor = plugin.Processor;
const textlintKernelProcessor: TextlintPluginProcessorConstructor = plugin.Processor;
assert.ok(
typeof textlintKernelProcessor.availableExtensions === "function",
`Processor(${textlintKernelProcessor.name} should have availableExtensions()`
Expand Down Expand Up @@ -166,7 +166,7 @@ export class TextlintKernel {
text,
options
}: {
processor: TextlintKernelProcessor;
processor: TextlintPluginProcessor;
text: string;
options: TextlintKernelOptions;
}) {
Expand Down Expand Up @@ -212,7 +212,7 @@ export class TextlintKernel {
text,
options
}: {
processor: TextlintKernelProcessor;
processor: TextlintPluginProcessor;
text: string;
options: TextlintKernelOptions;
}): Promise<TextlintFixResult> {
Expand Down
6 changes: 3 additions & 3 deletions packages/@textlint/kernel/src/util/proccesor-helper.ts
@@ -1,18 +1,18 @@
// LICENSE : MIT
"use strict";
import * as assert from "assert";
import { TextlintKernelProcessor, TextlintKernelProcessorConstructor } from "../textlint-kernel-interface";
import { TextlintPluginProcessor, TextlintPluginProcessorConstructor } from "../textlint-kernel-interface";

/**
* find processor with `ext`
* @param {Processor[]} processors
* @param {string} ext
* @returns {Processor}
*/
export function getProcessorMatchExtension(processors: TextlintKernelProcessor[], ext: string) {
export function getProcessorMatchExtension(processors: TextlintPluginProcessor[], ext: string) {
const matchProcessors = processors.filter(processor => {
// static availableExtensions() method
const processorConstructor: TextlintKernelProcessorConstructor = processor.constructor as any;
const processorConstructor: TextlintPluginProcessorConstructor = processor.constructor as any;
assert(
typeof processorConstructor.availableExtensions === "function",
`Processor(${processorConstructor.name} should have availableExtensions()`
Expand Down
4 changes: 2 additions & 2 deletions packages/@textlint/kernel/test/helper/ExamplePlugin.ts
@@ -1,13 +1,13 @@
// MIT © 2017 azu
import { TextlintKernelProcessor, TextlintPluginCreator } from "../../src/textlint-kernel-interface";
import { TextlintPluginProcessor, TextlintPluginCreator } from "../../src/textlint-kernel-interface";

const parse = require("markdown-to-ast").parse;

export interface ExampleProcessorOptions {
testOption: string;
}

export class ExampleProcessor implements TextlintKernelProcessor {
export class ExampleProcessor implements TextlintPluginProcessor {
static availableExtensions() {
return [".md"];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@textlint/kernel/tsconfig.json
Expand Up @@ -6,7 +6,7 @@
"newLine": "LF",
"outDir": "./lib/",
"target": "es5",
"sourceMap": false, // SourceMap by babel
"sourceMap": false,
"declaration": true,
"jsx": "preserve",
"lib": [
Expand Down
6 changes: 3 additions & 3 deletions packages/textlint-fixer-formatter/package.json
Expand Up @@ -2,16 +2,16 @@
"name": "textlint-fixer-formatter",
"version": "1.0.0",
"description": "textlint output formatter for fixer",
"main": "lib/index.js",
"types": "src/index.d.ts",
"main": "lib/textlint-fixer-formatter/src/index.js",
"types": "lib/textlint-fixer-formatter/src/index.d.ts",
"scripts": {
"clean": "rimraf lib/",
"prepublish": "npm run build",
"build": "cross-env NODE_ENV=production tsc -p .",
"test": "mocha test"
},
"files": [
"lib/",
"lib/textlint-fixer-formatter",
"src/"
],
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/textlint-fixer-formatter/src/formatters/compats.ts
@@ -1,6 +1,6 @@
// LICENSE : MIT
"use strict";
import { TextlintTypes } from "@textlint/kernel";
import { TextlintFixResult } from "@textlint/kernel";
function getMessageType(message: any) {
if (message.fatal || message.severity === 2) {
return "Error";
Expand All @@ -9,7 +9,7 @@ function getMessageType(message: any) {
}
}

export function format(results: TextlintTypes.TextlintFixResult[]) {
export function format(results: TextlintFixResult[]) {
let output = "";
let total = 0;

Expand Down
4 changes: 2 additions & 2 deletions packages/textlint-fixer-formatter/src/formatters/diff.ts
Expand Up @@ -3,7 +3,7 @@ const fs = require("fs");
const isFile = require("is-file");
const jsdiff = require("diff");
const chalk = require("chalk");
import { TextlintTypes } from "@textlint/kernel";
import { TextlintFixResult } from "@textlint/kernel";
/**
* Given a word and a count, append an s if count is not one.
* @param {string} word A word in its singular form.
Expand Down Expand Up @@ -31,7 +31,7 @@ function addMarkEachLine(mark: string, text: any) {
return `${markedLines.join("\n")}\n`;
}

export default function(results: TextlintTypes.TextlintFixResult[], options: any) {
export default function(results: TextlintFixResult[], options: any) {
// default: true
chalk.enabled = options.color !== undefined ? options.color : true;
let output = "\n";
Expand Down
4 changes: 2 additions & 2 deletions packages/textlint-fixer-formatter/src/formatters/json.ts
@@ -1,6 +1,6 @@
// LICENSE : MIT
"use strict";
import { TextlintTypes } from "@textlint/kernel";
export default function(results: TextlintTypes.TextlintFixResult[]) {
import { TextlintFixResult } from "@textlint/kernel";
export default function(results: TextlintFixResult[]) {
return JSON.stringify(results);
}
4 changes: 2 additions & 2 deletions packages/textlint-fixer-formatter/src/formatters/stylish.ts
Expand Up @@ -2,7 +2,7 @@
const chalk = require("chalk");
const table = require("text-table");
const widthOfString = require("string-width");
import { TextlintTypes } from "@textlint/kernel";
import { TextlintFixResult } from "@textlint/kernel";

/**
* Given a word and a count, append an s if count is not one.
Expand All @@ -14,7 +14,7 @@ function pluralize(word: string, count: number): string {
return count === 1 ? word : `${word}s`;
}

export default function(results: TextlintTypes.TextlintFixResult[], options: any) {
export default function(results: TextlintFixResult[], options: any) {
// default: true
chalk.enabled = options.color !== undefined ? options.color : true;
let output = "\n";
Expand Down
4 changes: 0 additions & 4 deletions packages/textlint-fixer-formatter/src/index.d.ts

This file was deleted.

0 comments on commit 442c297

Please sign in to comment.