Skip to content

fix(typescript-estree): parsing error for vue sfc #1083

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

Merged
merged 2 commits into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ function getProgramsForProjects(
results.push(program);
}

parsedFilesSeen.add(filePath);
return results;
}

Expand All @@ -216,11 +215,13 @@ function createWatchProgram(

// ensure readFile reads the code being linted instead of the copy on disk
const oldReadFile = watchCompilerHost.readFile;
watchCompilerHost.readFile = (filePath, encoding): string | undefined =>
path.normalize(filePath) ===
path.normalize(currentLintOperationState.filePath)
watchCompilerHost.readFile = (filePath, encoding): string | undefined => {
parsedFilesSeen.add(filePath);
return path.normalize(filePath) ===
path.normalize(currentLintOperationState.filePath)
? currentLintOperationState.code
: oldReadFile(filePath, encoding);
};

// ensure process reports error on failure instead of exiting process immediately
watchCompilerHost.onUnRecoverableConfigFileDiagnostic = diagnosticReporter;
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/fixtures/vue-sfc/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ env:
es6: true
node: true

extends:
plugin:vue/essential

parserOptions:
# Local version of @typescript-eslint/parser
parser: '@typescript-eslint/parser'
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/fixtures/vue-sfc/World.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- World.vue -->
<template>
<div>
<div :id="name">
{{ enthusiasm }}
</div>
<button @click="decrement">-</button>
<button @click="increment">+</button>
</div>
</template>

<script lang="ts">
import Vue from "vue";
export default Vue.extend({
props: ['name', 'initialEnthusiasm'],
data() {
return {
enthusiasm: this.initialEnthusiasm,
}
},
methods: {
increment() { this.enthusiasm++; },
decrement() {
if (this.enthusiasm > 1) {
this.enthusiasm--;
}
},
}
});
</script>
8 changes: 8 additions & 0 deletions tests/integration/fixtures/vue-sfc/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,13 @@ export default Vue.extend({
",
"warningCount": 0,
},
Object {
"errorCount": 0,
"filePath": "/usr/linked/World.vue",
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"messages": Array [],
"warningCount": 0,
},
]
`;
3 changes: 3 additions & 0 deletions tests/integration/fixtures/vue-sfc/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ npm install $(npm pack /usr/eslint-plugin | tail -1)
# Install the latest vue-eslint-parser (this may break us occassionally, but it's probably good to get that feedback early)
npm install vue-eslint-parser@latest

# Install the latest eslint-plugin-vue (this may break us occassionally, but it's probably good to get that feedback early)
npm install eslint-plugin-vue@latest

# Run the linting
# (the "|| true" helps make sure that we run our tests on failed linting runs as well)
npx eslint --format json --output-file /usr/lint-output.json --config /usr/linked/.eslintrc.yml /usr/linked/**/*.vue || true
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/fixtures/vue-sfc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"compilerOptions": {
"strict": true
}
}
},
"include": [
"*.vue"
]
}