• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ES2PANDA_PARSER_CORE_ETS_NOLINT_PARSER_H
17 #define ES2PANDA_PARSER_CORE_ETS_NOLINT_PARSER_H
18 
19 #include "lexer/lexer.h"
20 #include "ETSparser.h"
21 
22 namespace ark::es2panda::parser {
23 
24 class ETSNolintParser {
25 public:
26     explicit ETSNolintParser(ParserImpl *mainParser);
27     void CollectETSNolints();
28     void ApplyETSNolintsToStatements(ArenaVector<ir::Statement *> &statements) const;
29 
30 private:
31     void SetStartPos();
32     void NextSymbol();
33     void BackwardSymbol();
34     void NextSymbol(std::size_t i);
35     void BackwardSymbol(std::size_t i);
36     void RewindToStart() const;
37 
38     char32_t PeekSymbol() const;
39     bool TryPeekU32String(const std::u32string &str);
40     bool IsEtsNolint();
41     bool IsNextLine();
42     bool IsBegin();
43     bool IsEnd();
44 
45     std::set<ETSWarnings> ParseETSNolintArgs();
46     bool ValidETSNolintArg(const std::string &warningName) const;
47     ETSWarnings MapETSNolintArg(const std::string &warningName) const;
48 
49     void AddToETSNolintLinesCollection(std::size_t line, const std::set<ETSWarnings> &collection);
50     bool IsLineWithETSNolint(const std::size_t line) const;
51     std::set<ETSWarnings> GetWarningsCollectionByLine(std::size_t line) const;
52 
53     void ApplyETSNolintsToNodesRecursively(ir::AstNode *node) const;
54 
55     ParserImpl *parser_;
56     std::size_t startPos_ = 0;
57     std::size_t posOffset_ = 0;
58     std::size_t line_ = 0;
59     std::set<ETSWarnings> applyingCollection_;
60     std::map<size_t, std::set<ETSWarnings>> linesCollection_;
61 };
62 }  // namespace ark::es2panda::parser
63 #endif
64