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

extensions option doesn't work for multiple extension. #623

Open
hata6502 opened this issue Aug 3, 2019 · 3 comments
Open

extensions option doesn't work for multiple extension. #623

hata6502 opened this issue Aug 3, 2019 · 3 comments
Labels
Status: PR Welcome Welcome to Pull Request Status: Proposal Request for comments

Comments

@hata6502
Copy link
Contributor

hata6502 commented Aug 3, 2019

What version of textlint are you using?

v11.3.1

What file type (Markdown, plain text, etc.) are you using?
Laravel Blade (.blade.php)

What did you do? Please include the actual source code causing the issue.
I tried to check Laravel Blade as html.
So I set .textlintrc.json to the following.

{
  "filters": {
    "comments": true
  },
  "plugins": {
    "html": {
      "extensions": [
        ".blade.php"
      ]
    }
  },
  "rules": {
    "preset-japanese": true,
    "preset-jtf-style": {
      "3.1.1.全角文字と半角文字の間": false
    },
    "prh": {
      "rulePaths": [
        "node_modules/prh/prh-rules/media/WEB+DB_PRESS.yml"
      ]
    }
  }
}

But textlint doesn't detect .blade.php files as html.

What did you expect to happen?
I think textlint doesn't support multiple extension (i.e. .blade.php, .tar.gz, etc).
When .textlintrc.json was set to the following,

    "html": {
      "extensions": [
        ".php"
      ]
    }

textlint detected .blade.php as html correctly.

What actually happened? Please include the actual, raw output from textlint.

Here is debug log.

hato@hato-YOGA:~/pencil$ node_modules/.bin/textlint --debug pencil/resources/views/index.blade.php 
  textlint:cli textlint --version: 11.3.1 +0ms
  textlint:cli Running on files, stdin-filename: undefined +2ms
  textlint:module-loader config Config {
  textlint:module-loader   configFile: '/home/hato/pencil/.textlintrc.json',
  textlint:module-loader   rulesBaseDirectory: undefined,
  textlint:module-loader   disabledRules: [],
  textlint:module-loader   rules: [ 'prh' ],
  textlint:module-loader   disabledFilterRules: [],
  textlint:module-loader   filterRules: [ 'comments' ],
  textlint:module-loader   presets: [ 'japanese', 'jtf-style' ],
  textlint:module-loader   plugins: [ 'html' ],
  textlint:module-loader   pluginsConfig: { html: { extensions: [Array] } },
  textlint:module-loader   rulesConfig:
  textlint:module-loader    { 'japanese/max-ten': { max: 3 },
  textlint:module-loader      'japanese/no-doubled-conjunctive-particle-ga': true,
  textlint:module-loader      'japanese/no-doubled-conjunction': true,
  textlint:module-loader      'japanese/no-double-negative-ja': true,
  textlint:module-loader      'japanese/no-doubled-joshi': { min_interval: 1 },
  textlint:module-loader      'japanese/sentence-length': { max: 100 },
  textlint:module-loader      'japanese/no-dropping-the-ra': true,
  textlint:module-loader      'japanese/no-mix-dearu-desumasu': true,
  textlint:module-loader      'japanese/no-nfd': true,
  textlint:module-loader      'japanese/no-invalid-control-character': true,
  textlint:module-loader      'jtf-style/1.1.1.本文': true,
  textlint:module-loader      'jtf-style/1.1.2.見出し': true,
  textlint:module-loader      'jtf-style/1.1.3.箇条書き': true,
  textlint:module-loader      'jtf-style/1.1.5.図表のキャプション': true,
  textlint:module-loader      'jtf-style/1.2.1.句点(。)と読点(、)': true,
  textlint:module-loader      'jtf-style/1.2.2.ピリオド(.)とカンマ(,)': true,
  textlint:module-loader      'jtf-style/2.1.2.漢字': false,
  textlint:module-loader      'jtf-style/2.1.5.カタカナ': false,
  textlint:module-loader      'jtf-style/2.1.6.カタカナの長音': false,
  textlint:module-loader      'jtf-style/2.1.8.算用数字': true,
  textlint:module-loader      'jtf-style/2.1.9.アルファベット': true,
  textlint:module-loader      'jtf-style/2.1.10.算用数字の位取りの表記': true,
  textlint:module-loader      'jtf-style/2.2.1.ひらがなと漢字の使い分け': false,
  textlint:module-loader      'jtf-style/2.2.2.算用数字と漢数字の使い分け': true,
  textlint:module-loader      'jtf-style/2.2.3.一部の助数詞の表記': true,
  textlint:module-loader      'jtf-style/3.1.1.全角文字と半角文字の間': false,
  textlint:module-loader      'jtf-style/3.1.2.全角文字どうし': true,
  textlint:module-loader      'jtf-style/3.2.カタカナ語間のスペースの有無': true,
  textlint:module-loader      'jtf-style/3.3.かっこ類と隣接する文字の間のスペースの有無': true,
  textlint:module-loader      'jtf-style/4.1.1.句点(。)': true,
  textlint:module-loader      'jtf-style/4.1.3.ピリオド(.)、カンマ(,)': true,
  textlint:module-loader      'jtf-style/4.2.1.感嘆符(!)': true,
  textlint:module-loader      'jtf-style/4.2.2.疑問符(?)': true,
  textlint:module-loader      'jtf-style/4.2.4.中黒(・)': true,
  textlint:module-loader      'jtf-style/4.2.5.波線(〜)': true,
  textlint:module-loader      'jtf-style/4.2.6.ハイフン(-)': true,
  textlint:module-loader      'jtf-style/4.2.7.コロン(:)': true,
  textlint:module-loader      'jtf-style/4.2.8.セミコロン(;)': true,
  textlint:module-loader      'jtf-style/4.2.9.ダッシュ(-)': true,
  textlint:module-loader      'jtf-style/4.3.1.丸かっこ()': true,
  textlint:module-loader      'jtf-style/4.3.2.大かっこ[]': true,
  textlint:module-loader      'jtf-style/4.3.3.かぎかっこ「」': true,
  textlint:module-loader      'jtf-style/4.3.4.二重かぎかっこ『』': true,
  textlint:module-loader      'jtf-style/4.3.5.二重引用符': true,
  textlint:module-loader      'jtf-style/4.3.6.中かっこ{ }': true,
  textlint:module-loader      'jtf-style/4.3.7.山かっこ<>': true,
  textlint:module-loader      'jtf-style/4.3.8.一重引用符': true,
  textlint:module-loader      prh: { rulePaths: [Array] } },
  textlint:module-loader   filterRulesConfig: { comments: true },
  textlint:module-loader   rulePaths: [],
  textlint:module-loader   formatterName: undefined,
  textlint:module-loader   quiet: false,
  textlint:module-loader   color: true,
  textlint:module-loader   cache: false,
  textlint:module-loader   cacheLocation: '/home/hato/pencil/.textlintcache' } +0ms
  textlint:module-loader Loading rules from /home/hato/pencil/node_modules/textlint-rule-prh/lib/textlint-rule-prh.js +4ms
  textlint:module-loader Loading filter rules from /home/hato/pencil/node_modules/textlint-filter-rule-comments/lib/textlint-filter-rule-comments.js +0ms
  textlint:module-loader Loading rules from preset: /home/hato/pencil/node_modules/textlint-rule-preset-japanese/lib/textlint-rule-preset-japanese.js +1ms
  textlint:module-loader Loading rules from preset: /home/hato/pencil/node_modules/textlint-rule-preset-jtf-style/lib/index.js +1ms
  textlint:module-loader Loading rules from plugin: /home/hato/pencil/node_modules/textlint-plugin-html/lib/index.js +0ms
  textlint:engine-core Process files [] +0ms
  textlint:engine-core No Process files that are un-support extensions: [ '/home/hato/pencil/pencil/resources/views/index.blade.php' ] +0ms
  textlint:cli lint results: [] +1s
  textlint:@textlint/linter-formatter formatterName: stylish +0ms
hato@hato-YOGA:~/pencil$ 
@azu
Copy link
Member

azu commented Oct 19, 2019

I have no idea for multiple extensions.
We need to research that other program like ESLint, Editor(VSCode, Atom) support it.

📝 Note: textlint just use path.extname(path) and it return .php from file.foo.php.

@azu azu added the Status: Need More Info Lacks enough info to make progress label Oct 19, 2019
@MartinBonner
Copy link

I think the solution is likely to be the equivalent of the following python

    for suffix in suffix_list:
        if path.endswith(suffix)
            return True
    return False

rather than the current

    return path.extname(path) in suffix_list

(Apologies for the python code, but I can only read js rather than writing it, and I think the idea is clear.)

@azu azu added Status: Proposal Request for comments and removed Status: Need More Info Lacks enough info to make progress labels Dec 19, 2021
@azu
Copy link
Member

azu commented Dec 21, 2021

I think that endswith approach is reasonable.

findPluginDescriptorWithExt(ext: string) {
return this.descriptors.find((descriptor) => {
return descriptor.availableExtensions.includes(ext);
});
}

 findPluginDescriptorWithExt(ext: string) { 
     return this.descriptors.find((descriptor) => { 
         // availableExtensions are defined by each plugins
         // ext is current process file extension
         // e.g. 
         // If availableExtensions: [".php"]
         // ext: ".php" → match
         // ext: ".blade.php" → match
         // ext: ".php.txt" →  does not match
         return descriptor.availableExtensions.some(availableExtension => ext.endsWith(availableExtension)); 
     }); 
 } 

@azu azu added the Status: PR Welcome Welcome to Pull Request label Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: PR Welcome Welcome to Pull Request Status: Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

3 participants