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

@textlint/browser #299

Open
azu opened this Issue Sep 15, 2017 · 10 comments

Comments

Projects
None yet
2 participants
@azu
Member

azu commented Sep 15, 2017

We have noticed that some browser application use textlint.
(But some app use Node.js as backend like Electron)

Currently, @textlint/kernel provide low-level API.
But, it is unusable and it is almost internal API. Because kernel's version < 1.0.

We want to provide high-level API for browser.

Name

@textlint/browser

Feature

Any idea?

  • lintText(text, options): Promise
  • WebWorker support
    • Linting is heavy task
    • It is good thing for browser
  • How to load .textlintrc?
    • Loading is out of scope

Limitation

Some rules are not work on browser because some rules depended on Node.js.
We should careful about error handling.

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu Mar 11, 2018

Member

I think that to support WebWorker is good thing.
Web Workers to the rescue – Rastislav Svarba – Medium

Member

azu commented Mar 11, 2018

I think that to support WebWorker is good thing.
Web Workers to the rescue – Rastislav Svarba – Medium

@Leko

This comment has been minimized.

Show comment
Hide comment
@Leko

Leko May 24, 2018

Member

How to load rule and plugin, and config?

I think it is better to define rules like a Babel.

{
  rules: [
    [require('textlint-rule-prh'), {
      ruleContents: [
        `YAML content...`,
      ]
    }]
  ]
}

And using it as below:

import { lintText, lintMarkdown } from '@textlint/browser'

const config = {
  rules: // like above format
}

const text = 'Hello'
const result = await lintText(text, config)

const markdown = '# Hello'
const result2 = await lintMarkdown(markdown, config)

How to load .textlintrc?

I think we don't need support to load .textlintrc.
If anyone want to use .textlintrc, use with Webpack (raw-loader):

import { lintText } from '@textlint/browser'
import textlintrc from './.textlintrc'

const config = JSON.parse(textlintrc)
lintText('...', config)

@azu How about you?

Member

Leko commented May 24, 2018

How to load rule and plugin, and config?

I think it is better to define rules like a Babel.

{
  rules: [
    [require('textlint-rule-prh'), {
      ruleContents: [
        `YAML content...`,
      ]
    }]
  ]
}

And using it as below:

import { lintText, lintMarkdown } from '@textlint/browser'

const config = {
  rules: // like above format
}

const text = 'Hello'
const result = await lintText(text, config)

const markdown = '# Hello'
const result2 = await lintMarkdown(markdown, config)

How to load .textlintrc?

I think we don't need support to load .textlintrc.
If anyone want to use .textlintrc, use with Webpack (raw-loader):

import { lintText } from '@textlint/browser'
import textlintrc from './.textlintrc'

const config = JSON.parse(textlintrc)
lintText('...', config)

@azu How about you?

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu May 24, 2018

Member

I think it is better to define rules like a Babel.

textlint need to key of the rule/plugin.
The key is used for results of linting.

export interface TextlintMessage {
// See src/shared/type/MessageType.js
// Message Type
type: string;
// Rule Id
ruleId: string;
message: string;
// optional data
data?: any;
// FixCommand
fix?: TextlintFixCommand;
// location info
// Text -> AST TxtNode(0-based columns) -> textlint -> TextlintMessage(**1-based columns**)
line: number; // start with 1
column: number; // start with 1
// indexed-location
index: number; // start with 0
// Severity Level
// See src/shared/type/SeverityLevel.js
severity: number;
}

This is the reason that kernel require ruleId for opions.

const options = {
    filePath: "/path/to/file.md",
    ext: ".md",
    plugins: [
        {
            pluginId: "markdown",
            plugin: require("@textlint/textlint-plugin-markdown")
        }
    ],
    rules: [
        {
            ruleId: "no-todo",
            rule: require("textlint-rule-no-todo")
        }
    ]
};
Member

azu commented May 24, 2018

I think it is better to define rules like a Babel.

textlint need to key of the rule/plugin.
The key is used for results of linting.

export interface TextlintMessage {
// See src/shared/type/MessageType.js
// Message Type
type: string;
// Rule Id
ruleId: string;
message: string;
// optional data
data?: any;
// FixCommand
fix?: TextlintFixCommand;
// location info
// Text -> AST TxtNode(0-based columns) -> textlint -> TextlintMessage(**1-based columns**)
line: number; // start with 1
column: number; // start with 1
// indexed-location
index: number; // start with 0
// Severity Level
// See src/shared/type/SeverityLevel.js
severity: number;
}

This is the reason that kernel require ruleId for opions.

const options = {
    filePath: "/path/to/file.md",
    ext: ".md",
    plugins: [
        {
            pluginId: "markdown",
            plugin: require("@textlint/textlint-plugin-markdown")
        }
    ],
    rules: [
        {
            ruleId: "no-todo",
            rule: require("textlint-rule-no-todo")
        }
    ]
};
@Leko

This comment has been minimized.

Show comment
Hide comment
@Leko

Leko May 25, 2018

Member

@azu Ah sorry.
Then, I think the better format is array of object.

    rules: [
        {
            ruleId: "no-todo",
            rule: require("textlint-rule-no-todo")
        },
        {
            ruleId: "rule-aaa",
            rule: require("textlint-rule-aaa"),
            option: { ... },
        },
    ]

WebWorker support

I think we should support WebWorker.
Textlint does not depend on DOM and TextlintMessage is transferable.

Member

Leko commented May 25, 2018

@azu Ah sorry.
Then, I think the better format is array of object.

    rules: [
        {
            ruleId: "no-todo",
            rule: require("textlint-rule-no-todo")
        },
        {
            ruleId: "rule-aaa",
            rule: require("textlint-rule-aaa"),
            option: { ... },
        },
    ]

WebWorker support

I think we should support WebWorker.
Textlint does not depend on DOM and TextlintMessage is transferable.

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu May 25, 2018

Member

I think we should support WebWorker.

Yes. Probaly, main use-case of textlint/browser is an editor like application.
That app run linting with high frequency.
This task should be split to non-main thread.

I have known that hls.js has built-in worker process.

Member

azu commented May 25, 2018

I think we should support WebWorker.

Yes. Probaly, main use-case of textlint/browser is an editor like application.
That app run linting with high frequency.
This task should be split to non-main thread.

I have known that hls.js has built-in worker process.

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu May 25, 2018

Member

Overview of textlint

image

https://github.com/textlint/textlint/tree/master/packages/textlint/src

textlint includes CLI, Engine, and Core. (This term is historical reasons...)
@textlint/kernel is Kernel.

Probably, @textlint/browser is a sister/brother of Core.
Engine's tasks include loading of .textlintrc.
As a result, we can drop loading task(load .textlinrc and parse it) from @textlint/browser.

Member

azu commented May 25, 2018

Overview of textlint

image

https://github.com/textlint/textlint/tree/master/packages/textlint/src

textlint includes CLI, Engine, and Core. (This term is historical reasons...)
@textlint/kernel is Kernel.

Probably, @textlint/browser is a sister/brother of Core.
Engine's tasks include loading of .textlintrc.
As a result, we can drop loading task(load .textlinrc and parse it) from @textlint/browser.

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu May 25, 2018

Member

We might well have started with creating @textlint/browser as is a wrapper of kernel with WebWorker support.

@textlint/browser = @textlint/kernel + WebWorker + α

@Leko How about you?

Member

azu commented May 25, 2018

We might well have started with creating @textlint/browser as is a wrapper of kernel with WebWorker support.

@textlint/browser = @textlint/kernel + WebWorker + α

@Leko How about you?

@Leko

This comment has been minimized.

Show comment
Hide comment
@Leko

Leko May 27, 2018

Member

@azu I'm sorry for my late reply.

Probably, @textlint/browser is a sister/brother of Core.

@textlint/browser = @textlint/kernel + WebWorker + α

I agree with this plan.
I think core(TextLintCore) is unnecessary to lint in a browser.

Member

Leko commented May 27, 2018

@azu I'm sorry for my late reply.

Probably, @textlint/browser is a sister/brother of Core.

@textlint/browser = @textlint/kernel + WebWorker + α

I agree with this plan.
I think core(TextLintCore) is unnecessary to lint in a browser.

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu May 29, 2018

Member

We can use playground as MVP(Minimum Viable Product).
It is a just editor that work on browser.

I think that we should have experimental product(like playground app) which use @textlint/browser.
We can start to create a library after we can get actual needs.
It is good process to create good library.

Do you have any product that you want to create?

Member

azu commented May 29, 2018

We can use playground as MVP(Minimum Viable Product).
It is a just editor that work on browser.

I think that we should have experimental product(like playground app) which use @textlint/browser.
We can start to create a library after we can get actual needs.
It is good process to create good library.

Do you have any product that you want to create?

@Leko

This comment has been minimized.

Show comment
Hide comment
@Leko

Leko May 30, 2018

Member

We can start to create a library after we can get actual needs.

I think so too.

I already created markdown editor(uses monaco-editor, Textlint kernel and React Native for Web etc).
But it is for internal use. I can't publish it as OSS.

Another one, I got nothing for now.

Member

Leko commented May 30, 2018

We can start to create a library after we can get actual needs.

I think so too.

I already created markdown editor(uses monaco-editor, Textlint kernel and React Native for Web etc).
But it is for internal use. I can't publish it as OSS.

Another one, I got nothing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment