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

🐛 @biome/js-api diagnostic generate incorrect span range when content has non-ASCII characters #4035

Open
1 task done
axetroy opened this issue Sep 22, 2024 · 0 comments

Comments

@axetroy
Copy link

axetroy commented Sep 22, 2024

Environment information

CLI:
  Version:                      1.9.2
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           windows

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         unset
  JS_RUNTIME_VERSION:           "v16.20.2"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    true
  VCS disabled:                 true

Workspace:
  Open Documents:               0

What happened?

    "dependencies": {
        "@biomejs/js-api": "^0.6.2",
        "@biomejs/wasm-nodejs": "^1.8.4-nightly.d079e53",
        "outdent": "^0.8.0"
    }

@biomejs/wasm-nodejs@1.9.2 is not compatible with @biomejs/js-api, see #3881

When I try to lint content, and it generate incorrect span range

✅ English characters:

const { Biome, Distribution } = require('@biomejs/js-api')

async function main() {
    const biome = await Biome.create({
        distribution: Distribution.NODE
    })

    const input = '/** English comment */ let a = 123'

    const result = biome.lintContent(input, { filePath: 'index.js' })

    for (const diagnostic of result.diagnostics) {
        const [start, end] = diagnostic.location.span

        const span = input.slice(start, end)

        console.log('start -->', start, 'end -->', end, 'span -->', span)

        // start --> 23 end --> 26 span --> let
    }
}

main()

❌ Chinese characters:

const { Biome, Distribution } = require('@biomejs/js-api')

async function main() {
    const biome = await Biome.create({
        distribution: Distribution.NODE
    })

    const input = '/** 中文注释 */ let a = 123'

    const result = biome.lintContent(input, { filePath: 'index.js' })

    for (const diagnostic of result.diagnostics) {
        const [start, end] = diagnostic.location.span

        const span = input.slice(start, end)

        console.log('start -->', start, 'end -->', end, 'span -->', span)

        // start --> 20 end --> 23 span --> 123
    }
}

main()

❌ Japanese characters:

const { Biome, Distribution } = require('@biomejs/js-api')

async function main() {
    const biome = await Biome.create({
        distribution: Distribution.NODE
    })

    const input = '/** 日本語注釈 */ let a = 123'

    const result = biome.lintContent(input, { filePath: 'index.js' })

    for (const diagnostic of result.diagnostics) {
        const [start, end] = diagnostic.location.span

        const span = input.slice(start, end)

        console.log('start -->', start, 'end -->', end, 'span -->', span)

        // start --> 23 end --> 26 span --> 3
    }
}

main()

Expected result

The output span is incorrect

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@axetroy axetroy changed the title 🐛 @biome/js-api diagnostic generate incorrect span range 🐛 @biome/js-api diagnostic generate incorrect span range when content has non-English characters Sep 22, 2024
@axetroy axetroy changed the title 🐛 @biome/js-api diagnostic generate incorrect span range when content has non-English characters 🐛 @biome/js-api diagnostic generate incorrect span range when content has non-ASCII characters Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant