Repository: vuejs/eslint-plugin-vue (js)

Issue:
crash when using the vue/no-empty-component-block rule on a .js file
<!--
  Before posting the issue, please confirm that the problem you're getting
  is not related with your code editor configuration.
  To make sure it's not, run: yarn eslint src/your-file.vue
-->

**Tell us about your environment**	
* **ESLint version:** 7.3.1
* **eslint-plugin-vue version:** 7.0.0-alpha.8
* **Node version:**	v12.18.2

**Please show your full configuration:**
<!-- Paste content of your .eslintrc file -->
```js
{
  root: true,

  parserOptions: {
    sourceType: 'module'
  },

  env: {
    browser: true,
    node: true,
    es2020: true
  },

  extends: ['plugin:vue/vue3-recommended'],

  rules: [
    // *other rules*
    'vue/no-empty-component-block': 'error'
  ]
}
```

**What did you do?**	
I launched the linter for the .js file

**What did you expect to happen?**
plugin works

**What actually happened?**
```
Oops! Something went wrong! :(

ESLint: 7.3.1

TypeError: Error while loading rule 'vue/no-empty-component-block': Cannot read property 'children' of null
Occurred while linting C:\Users\danyadev\Desktop\vk-desktop\src\components\auth\index.js
    at Object.create (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint-plugin-vue\lib\rules\no-empty-component-block.js:75:7)
    at createRuleListeners (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\linter\linter.js:758:21)
    at C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\linter\linter.js:928:31
    at Array.forEach (<anonymous>)
    at runRules (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\linter\linter.js:873:34)
    at Linter._verifyWithoutProcessors (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\linter\linter.js:1170:31)
    at Linter._verifyWithConfigArray (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\linter\linter.js:1268:21)
    at Linter.verify (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\linter\linter.js:1223:25)
    at Linter.verifyAndFix (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\linter\linter.js:1413:29)
    at verifyText (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\cli-engine\cli-engine.js:224:48)
    at CLIEngine.executeOnFiles (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\cli-engine\cli-engine.js:788:28)
    at ESLint.lintFiles (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\eslint\eslint.js:515:23)
    at Object.execute (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\lib\cli.js:294:36)
    at main (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\bin\eslint.js:142:52)
    at Object.<anonymous> (C:\Users\danyadev\Desktop\vk-desktop\node_modules\eslint\bin\eslint.js:146:2)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
```


Pull request description:
Fixed crash when using `vue/no-empty-component-block` and `vue/padding-line-between-blocks` rules in `.js` file


Fixed #1230

Patch:
diff --git a/lib/rules/no-empty-component-block.js b/lib/rules/no-empty-component-block.js
index dc776705..6378dcd8 100644
--- a/lib/rules/no-empty-component-block.js
+++ b/lib/rules/no-empty-component-block.js
@@ -69,10 +69,12 @@ module.exports = {
     if (!context.parserServices.getDocumentFragment) {
       return {}
     }
+    const documentFragment = context.parserServices.getDocumentFragment()
+    if (!documentFragment) {
+      return {}
+    }
 
-    const componentBlocks = context.parserServices
-      .getDocumentFragment()
-      .children.filter(isVElement)
+    const componentBlocks = documentFragment.children.filter(isVElement)
 
     return {
       Program() {
diff --git a/lib/rules/padding-line-between-blocks.js b/lib/rules/padding-line-between-blocks.js
index b9215e2c..cc477370 100644
--- a/lib/rules/padding-line-between-blocks.js
+++ b/lib/rules/padding-line-between-blocks.js
@@ -139,12 +139,16 @@ module.exports = {
     if (!context.parserServices.getDocumentFragment) {
       return {}
     }
+    const df = context.parserServices.getDocumentFragment()
+    if (!df) {
+      return {}
+    }
+    const documentFragment = df
+
     /** @type {'always' | 'never'} */
     const option = context.options[0] || 'always'
     const paddingType = PaddingTypes[option]
 
-    const documentFragment = context.parserServices.getDocumentFragment()
-
     /** @type {Token[]} */
     let tokens
     /**
diff --git a/typings/eslint-plugin-vue/util-types/parser-services.ts b/typings/eslint-plugin-vue/util-types/parser-services.ts
index c2e68464..8f6e2a62 100644
--- a/typings/eslint-plugin-vue/util-types/parser-services.ts
+++ b/typings/eslint-plugin-vue/util-types/parser-services.ts
@@ -17,7 +17,7 @@ export interface ParserServices {
     templateBodyVisitor: TemplateListener,
     scriptVisitor?: eslint.Rule.RuleListener
   ) => eslint.Rule.RuleListener
-  getDocumentFragment?: () => VAST.VDocumentFragment
+  getDocumentFragment?: () => VAST.VDocumentFragment | null
 }
 export namespace ParserServices {
   export interface TokenStore {


Test patch:
diff --git a/tests/lib/rules-without-vue-sfc.js b/tests/lib/rules-without-vue-sfc.js
new file mode 100644
index 00000000..c1d5eb2b
--- /dev/null
+++ b/tests/lib/rules-without-vue-sfc.js
@@ -0,0 +1,31 @@
+/**
+ * @author Yosuke Ota <https://github.com/ota-meshi>
+ * See LICENSE file in root directory for full license.
+ */
+'use strict'
+
+const Linter = require('eslint').Linter
+const parser = require('vue-eslint-parser')
+const rules = require('../..').rules
+
+describe("Don't crash even if without vue SFC.", () => {
+  const code = 'var a = 1'
+
+  for (const key of Object.keys(rules)) {
+    const ruleId = `vue/${key}`
+
+    it(ruleId, () => {
+      const linter = new Linter()
+      const config = {
+        parser: 'vue-eslint-parser',
+        parserOptions: { ecmaVersion: 2015 },
+        rules: {
+          [ruleId]: 'error'
+        }
+      }
+      linter.defineParser('vue-eslint-parser', parser)
+      linter.defineRule(ruleId, rules[key])
+      linter.verifyAndFix(code, config, 'test.js')
+    })
+  }
+})
diff --git a/tests/lib/rules/no-empty-component-block.js b/tests/lib/rules/no-empty-component-block.js
index 92813aa2..8ba6a2f2 100644
--- a/tests/lib/rules/no-empty-component-block.js
+++ b/tests/lib/rules/no-empty-component-block.js
@@ -22,7 +22,8 @@ tester.run('no-empty-component-block', rule, {
     `<template src="./template.html"></template><script src="./script.js"></script>`,
     `<template src="./template.html" /><script src="./script.js" />`,
     `<template src="./template.html"></template><script src="./script.js"></script><style src="./style.css"></style>`,
-    `<template src="./template.html" /><script src="./script.js" /><style src="./style.css" />`
+    `<template src="./template.html" /><script src="./script.js" /><style src="./style.css" />`,
+    `var a = 1`
   ],
   invalid: [
     {
diff --git a/tests/lib/rules/padding-line-between-blocks.js b/tests/lib/rules/padding-line-between-blocks.js
index f81b2bbf..622839bd 100644
--- a/tests/lib/rules/padding-line-between-blocks.js
+++ b/tests/lib/rules/padding-line-between-blocks.js
@@ -83,7 +83,8 @@ tester.run('padding-line-between-blocks', rule, {
       <style></style>
       `,
       options: ['never']
-    }
+    },
+    `var a = 1`
   ],
   invalid: [
     {