Skip to content

Commit

Permalink
fix(typescript-estree): parsing error for vue sfc (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 authored and bradzacher committed Oct 20, 2019
1 parent 2fc9bd2 commit 7a8cce6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
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"
]
}

0 comments on commit 7a8cce6

Please sign in to comment.