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

Bug: TypeError: Cannot read properties of undefined (reading 'type') #16898

Closed
1 task
shasherazi opened this issue Feb 16, 2023 · 1 comment
Closed
1 task
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:needed

Comments

@shasherazi
Copy link

Environment

Node version: v19.6.0
npm version: 8.19.2
Local ESLint version: v8.34.0
Global ESLint version: none
Operating System: Linux

What parser are you using?

@babel/eslint-parser

What did you do?

Configuration
{
  "env": {
    "browser": true,
    "es6": true
  },
  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "requireConfigFile": false,
    "ecmaVersion": 2022,
    "sourceType": "module"
  },
  "extends": ["airbnb-base"],
  "ignorePatterns": ["dist/", "build/"]
}

const libraryBooks = document.querySelector('.data-book');
const titleName = document.getElementById('titleName');
const authorName = document.getElementById('authorName');
const form = document.getElementById('myForm');
class Library {
  constructor(id, author, title) {
    this.id = id;
    this.author = author;
    this.title = title;
  }

  // Local Storage
  static addLocalStorage(libraryContainer) {
    const storage = localStorage.setItem(
      'books',
      JSON.stringify(libraryContainer),
    );
    return storage;
  }

  static getLocalStorage() {
    const storage = localStorage.getItem('books') === null
      ? []
      : JSON.parse(localStorage.getItem('books'));
    return storage;
  }

  // display in the DOM
  static displayBooks() {
    /* eslint-disable no-use-before-define */
    const displayData = libraryContainer.map(
      (item) => `
        <div class='books'>
        <p> "${item.title}" by ${item.author} </p>
        <button class="delete-btn" data-id= ${item.id}>Remove</button>
        </div>
        `,
    );
    libraryBooks.innerHTML = displayData.join(' ');
  }

  // clear input once submited
  static clearInput() {
    titleName.value = '';
    authorName.value = '';
  }

  // delete book from DOM and arraylibrar
  static deleteBook() {
    libraryBooks.addEventListener('click', (e) => {
      if (e.target.classList.contains('delete-btn')) {
        e.target.parentElement.remove();
      }
      const btnId = e.target.dataset.id;
      Library.removeLibraryArray(btnId);
    });
  }

  static removeLibraryArray(id) {
    libraryContainer = libraryContainer.filter((item) => item.id !== +id);
    Library.addLocalStorage(libraryContainer);
  }

  static currentDate() {
    const date = new Date();
    document.getElementById('dateDisplay').innerHTML = date;
  }
}
// innitialize form submit to create Library instance
form.addEventListener('submit', (e) => {
  e.preventDefault();
  const id = Math.floor(Math.random() * 1000);
  const book = new Library(id, authorName.value, titleName.value);
  libraryContainer.push(book);
  Library.displayBooks();
  Library.clearInput();
  Library.deleteBook();
  Library.addLocalStorage(libraryContainer);
});
window.addEventListener('DOMContentLoaded', () => {
  Library.displayBooks();
  Library.deleteBook();
  Library.currentDate();
});
// store values in a container referrenced by local storage
let libraryContainer = Library.getLocalStorage();
// Single Page Application
const books = document.querySelector('.listone');
const addNew = document.querySelector('.listtwo');
const contact = document.querySelector('.listthree');
const booksContainer = document.getElementById('booksContainer');
const contactContainer = document.getElementById('contact');
books.addEventListener('click', () => {
  booksContainer.style.display = 'block';
  form.style.display = 'none';
  contactContainer.style.display = 'none';
});
addNew.addEventListener('click', () => {
  booksContainer.style.display = 'none';
  form.style.display = 'block';
  contactContainer.style.display = 'none';
});
contact.addEventListener('click', () => {
  contactContainer.style.display = 'block';
  booksContainer.style.display = 'none';
  form.style.display = 'none';
});

What did you expect to happen?

No error

What actually happened?

Oops! Something went wrong! :(

ESLint: 8.34.0

TypeError: Cannot read properties of undefined (reading 'type')
Occurred while linting /home/shasherazi/programming/microverse/awesom-books/app.js:1
at /home/shasherazi/programming/microverse/awesom-books/node_modules/esquery/dist/esquery.min.js:1:29469
at /home/shasherazi/programming/microverse/awesom-books/node_modules/esquery/dist/esquery.min.js:1:30512
at b.matches (/home/shasherazi/programming/microverse/awesom-books/node_modules/esquery/dist/esquery.min.js:1:34848)
at NodeEventGenerator.applySelector (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/node-event-generator.js:296:21)
at NodeEventGenerator.applySelectors (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/node-event-generator.js:324:22)
at NodeEventGenerator.enterNode (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
at CodePathAnalyzer.enterNode (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:795:23)
at /home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/linter.js:1153:32
at Array.forEach ()
at runRules (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/linter.js:1148:15)
at Linter._verifyWithoutProcessors (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/linter.js:1397:31)
at Linter._verifyWithConfigArray (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/linter.js:1772:21)
at Linter.verify (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/linter.js:1479:65)
at Linter.verifyAndFix (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/linter/linter.js:2031:29)
at verifyText (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/cli-engine/cli-engine.js:245:48)
at CLIEngine.executeOnFiles (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/cli-engine/cli-engine.js:823:28)
at ESLint.lintFiles (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/eslint/eslint.js:551:23)
at Object.execute (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/lib/cli.js:417:36)
at async main (/home/shasherazi/programming/microverse/awesom-books/node_modules/eslint/bin/eslint.js:135:24)

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

Many of my fellow students are facing this Oops! Something went wrong! :( which is causing blockers in their work. I cant seem to figure out the reason behind this

@shasherazi shasherazi added bug ESLint is working incorrectly repro:needed labels Feb 16, 2023
@mdjermanovic
Copy link
Member

Duplicate of #16896

@mdjermanovic mdjermanovic marked this as a duplicate of #16896 Feb 16, 2023
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Aug 16, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:needed
Projects
Archived in project
Development

No branches or pull requests

2 participants