1/* 2 * Copyright (c) 2021-2022 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 16const rules = require('../code_style_rule.json'); 17const { getAPINote, ErrorType, ErrorLevel, FileType } = require('./utils'); 18const { addAPICheckErrorLogs } = require('./compile_info'); 19 20function checkSyscap(node, sourcefile, fileName) { 21 const syscapRuleSet = new Set(rules.syscap.SystemCapability); 22 const apiNote = getAPINote(node); 23 const apiNoteArr = apiNote.split('*'); 24 let errorInfo = ''; 25 apiNoteArr.forEach(note => { 26 if (note.match(new RegExp('@syscap'))) { 27 const syscapNote = note.replace('@syscap', '').trim(); 28 if (!syscapRuleSet.has(syscapNote)) { 29 if (errorInfo !== '') { 30 errorInfo += `,${syscapNote}`; 31 } else { 32 errorInfo += syscapNote; 33 } 34 addAPICheckErrorLogs(node, sourcefile, fileName, ErrorType.UNKNOW_SYSCAP, errorInfo, FileType.JSDOC, 35 ErrorLevel.MIDDLE); 36 } 37 } 38 }); 39} 40exports.checkSyscap = checkSyscap; 41