OfficeDev / Office-Addin-Scripts

A set of scripts and packages that are consumed in Office add-ins projects.
MIT License
156 stars 99 forks source link

office-addin-lint with Vue #782

Closed Flyingdot closed 1 year ago

Flyingdot commented 1 year ago

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

Expected behavior

Linter works in Vue Projects with SFC (Single File Components)

Current behavior

When linting a vue-component in SFC-syntax, it fails with errors like this:

  2:9  error  Parsing error: '>' expected

a typical SFC looks like this (MyComponent.vue):

<script setup lang="ts">
Word.run(async (context) => {
   // ...
})
</script>

<template>
    <h1>Hello Office</h1>
</template>

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. npm i -D office-addin-lint check
  2. .eslint.cjs
    
    /* eslint-env node */
    require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = { root: true, plugins: ['office-addins'], extends: [ 'plugin:vue/vue3-essential', 'eslint:recommended', '@vue/eslint-config-typescript', '@vue/eslint-config-prettier/skip-formatting', 'plugin:office-addins/recommended' ], parserOptions: { ecmaVersion: 'latest' } }

3. `npm run lint`
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --ignore-path .gitignore",


## Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

* Operating System: macos
* Node version: 18.16.0
* Office version: 
* Tool version:     "office-addin-lint": "^2.2.5",
millerds commented 1 year ago

From what I understand about eslint and the eslint-plugin-vue pluging you may need to adjust your eslint config to support parsing the .vue files along with other types of script in it. See: https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser and https://github.com/vuejs/vue-eslint-parser#parseroptionsparser

FYI . . . tecnically office-addin-lint is basically a cli for linting basic ts and js files with a default eslint config. The actual rules for office.js are in eslint-plugin-office-addins (which is a dependency of office-addin-lint) which are built for typescript and javascript.

millerds commented 1 year ago

Please comment when you get new information.