api_check

Signed-off-by: yangbo_404 <yangbo198@huawei.com>
Change-Id: I2e0313e96307110219d894b7b6d07a7ffdc80b52
This commit is contained in:
yangbo_404 2022-12-12 20:36:24 +08:00
parent 5f74bcabaf
commit f334ef57b8
8 changed files with 222 additions and 62 deletions

View File

@ -1,4 +1,4 @@
{
"apiFiles":[],
"scanResult":[]
"apiFiles": [],
"scanResult": []
}

View File

@ -99,7 +99,7 @@
"name",
"undocumented"
],
"permission":[
"permission": [
"ANSWER_CALL",
"USE_BLUETOOTH",
"DISCOVER_BLUETOOTH",
@ -272,25 +272,25 @@
"BundleFramework.QuickFix",
"BundleFramework.AppControl"
],
"Developtools":[
"Developtools": [
"Syscap"
],
"Graphic":[
"Graphic": [
"Graphic2D.WebGL",
"Graphic2D.WebGL2",
"Graphic2D.ColorManager.Core"
],
"WindowManager":[
"WindowManager": [
"WindowManager.Core",
"WindowManager.MutiScreen"
],
"Notification":[
"Notification": [
"CommonEvent",
"Notification",
"ReminderAgent",
"Emitter"
],
"Communication":[
"Communication": [
"IPC.Core",
"SoftBus.Core",
"NetManager.Core",
@ -307,22 +307,22 @@
"ConnectedTag",
"NFC.Tag",
"NFC.CardEmulation",
"NFCManager.Ethernet",
"NFCManager.NetSharing",
"NFCManager.MDNS",
"NFCManager.Vpn"
"NetManager.Ethernet",
"NetManager.NetSharing",
"NetManager.MDNS",
"NetManager.Vpn"
],
"Location":[
"Location": [
"Location.Core",
"Location.Geocoder",
"Location.Geofence",
"Location.Gnss",
"Location.Lite"
],
"Msdp":[
"Msdp": [
"DeviceStatus.Stationary"
],
"MultimodalInput":[
"MultimodalInput": [
"Input.Core",
"Input.InputDevice",
"Input.RemoteInputDevice",
@ -333,7 +333,7 @@
"Input.Cooperator",
"Input.Pointer"
],
"PowerManager":[
"PowerManager": [
"BatteryManager.Extension",
"BatteryStatistics",
"DisplayPowerManager",
@ -344,7 +344,7 @@
"BatteryManager.Lite",
"PowerManager.Extension"
],
"Multimedia":[
"Multimedia": [
"Media.Core",
"Media.AudioPlayer",
"Media.AudioRecorder",
@ -360,6 +360,8 @@
"AVSession.Core",
"AVSession.Manager",
"Audio.Core",
"Audio.Tone",
"Audio.Interrupt",
"Audio.Renderer",
"Audio.Capturer",
"Audio.Device",
@ -378,7 +380,7 @@
"Media.AVRecorder",
"Image.ImageCreator"
],
"Telephony":[
"Telephony": [
"CoreService",
"CallManager",
"CellularCall",
@ -386,21 +388,21 @@
"SmsMms",
"StateRegistry"
],
"Global":[
"Global": [
"I18n",
"ResourceManager"
],
"Customization":[
"Customization": [
"ConfigPolicy",
"EnterpriseDeviceManager"
],
"BarrierFree":[
"BarrierFree": [
"Accessibility.Core",
"Accessibility.Vision",
"Accessibility.Hearing",
"Accessibility.Interaction"
],
"ResourceSchedule":[
"ResourceSchedule": [
"WorkScheduler",
"BackgroundTaskManager.ContinuousTask",
"BackgroundTaskManager.TransientTask",
@ -408,10 +410,10 @@
"UsageStatistics.AppGroup",
"BackgroundTaskManager.EfficiencyResourcesApply"
],
"Utils":[
"Utils": [
"Lang"
],
"HiviewDFX":[
"HiviewDFX": [
"HiLog",
"HiLogLite",
"HiTrace",
@ -425,13 +427,13 @@
"HiEventLite",
"HiProfiler.HiDebug"
],
"Update":[
"Update": [
"UpdateService"
],
"DistributedHardware":[
"DistributedHardware": [
"DeviceManager"
],
"Security":[
"Security": [
"DeviceAuth",
"DataTransitManager",
"DeviceSecurityLevel",
@ -444,16 +446,16 @@
"DataLossPrevention",
"Cert"
],
"Account":[
"Account": [
"OsAccount",
"AppAccount"
],
"UserIAM":[
"UserIAM": [
"UserAuth.Core",
"UserAuth.PinAuth",
"UserAuth.FaceAuth"
],
"MiscServices":[
"MiscServices": [
"InputMethodFramework",
"Pasteboard",
"Time",
@ -462,7 +464,7 @@
"Upload",
"Download"
],
"FileManagement":[
"FileManagement": [
"StorageService.Backup",
"StorageService.SpatialStatistics",
"StorageService.Volume",
@ -472,19 +474,20 @@
"File.DistributedFile",
"AppFileService",
"UserFileService",
"UserFileManager"
"UserFileManager",
"UserFileManager.Core"
],
"USB":[
"USB": [
"USBManager"
],
"Sensors":[
"Sensors": [
"Sensor",
"MiscDevice"
],
"Startup":[
"Startup": [
"SystemInfo"
],
"DistributedDataManager":[
"DistributedDataManager": [
"RelationalStore.Core",
"RelationalStore.Synchronize",
"RelationalStore.Lite",
@ -497,7 +500,7 @@
"DataShare.Consumer",
"DataShare.Provider"
],
"Ability":[
"Ability": [
"AbilityBase",
"AbilityRuntime.Core",
"AbilityRuntime.FAModel",
@ -508,18 +511,18 @@
"DistributedAbilityManager",
"AbilityRuntime.QuickFix"
],
"Applications":[
"Applications": [
"ContactsData",
"Contacts",
"settings.Core"
],
"Test":[
"Test": [
"UiTest"
],
"Web":[
"Web": [
"Webview.Core"
],
"Cloud":[
"Cloud": [
"AAID",
"OAID",
"VAID"

View File

@ -1,15 +1,20 @@
a256
a2dpsource
aafwk
abilityname
abilityslice
abnormally
accelerates
accents
accommodates
acmmax
activates
actived
adjusts
adpu
adts
agrees
alerting
algrithom
aligns
alpha
@ -22,20 +27,24 @@ antialias
apecified
appselect
arcs
arfcn
arrarybuffer
arraybuffer
arrlist
ashmem
associating
asy
asynchronized
atime
atio
atqa
attaches
attachment0
attribs
audios
authenticates
authinfo
autocorrect
avoidareachange
avrcp
avsession
@ -48,11 +57,15 @@ bgra
bidirectionally
bms
bolder
bonded
bonding
booted
brighter
brightest
browsable
bscribes
bsic
bssid
bufferfi
bufferfv
bufferiv
@ -64,16 +77,20 @@ buttonconfig
bypassed
bytrace
callbackfn
camped
canceling
cancelling
cancels
capabilitys
capturers
ccm
cdma
certsign
cft
channeldown
channelup
checkboxgroup
chload
chromaticities
chrominance
circled
@ -87,11 +104,14 @@ colno
complies
compresses
cone
conferencing
confpersist
connectable
contex
controlpanel
controlparam
convertxml
cpid
cpuprofiler
cpx
cpy
@ -101,6 +121,7 @@ crosshair
crowdtest
crowdtested
crowdtesting
cug
cyclewindows
daltonization
darkest
@ -109,6 +130,7 @@ datashare
datasync
dci
ddmp
deactivation
decodes
decompressed
decompressing
@ -122,6 +144,7 @@ denormalization
denormalize
denormalized
densitys
deregistered
deregisters
designative
desynchronized
@ -129,9 +152,12 @@ developtools
devicemanager
dfactor
dfx
dialling
dimbehind
dirent
disables
discharging
disconnecting
disconnection
disconnects
discription
@ -147,16 +173,22 @@ downlink
dpad
drains
drawbuffer
dsf
dtmf
ducked
ducking
earfcn
earphones
earpiece
efuse
egid
ehrpd
ejectclosecd
emption
encapsulates
encompassed
encrypts
endc
endx
endy
enrolled
@ -165,9 +197,11 @@ erasing
eration
errcode
erver
esim
ethiopic
ets
euid
evdo
evenodd
evicted
excepted
@ -178,29 +212,40 @@ faultlogger
fchmod
fchown
fdatasync
fdn
fdopen
fileio
fillets
flac
foldable
formatable
forwardmail
freesiza
freesize
fstat
fsync
ftruncate
fulfills
gamepad
gba
geofence
glasses
gnss
graphicseditor
greate
gtc
hailing
handheld
handhold
handsfree
handsfreeunit
hanguel
hangups
hanja
hankaku
hapmodule
haps
haptic
hce
headed
headersreceive
headphones
@ -208,29 +253,38 @@ heapsnapshot
heating
heavier
henkan
hfp
hibernates
hibernating
hichecker
hidebug
hierarchically
hifi
hilog
hisysevent
hitrace
hiview
hiviewdfx
hkdf
hspa
hspap
htmltext
huks
hwid
icq
idm
ifaces
ima
imager
imagevideo
imclient
imengine
immersive
imms
ims
imsi
inactived
inactivity
inclusiza
inconsistency
indata
@ -252,9 +306,15 @@ interleaved
internalformat
internationalized
interpolator
interworking
invalidates
ipaddr
isdn
isim
issuers
ivi
iwlan
jis
judged
kbdillum
kbdinputassist
@ -283,6 +343,7 @@ lifted
lintptr
listened
llbackfn
lockdown
lockscreen
lod
loggable
@ -301,31 +362,44 @@ luma
lushort
lux
mah
mcc
md5
mediaquery
meid
messageerror
metered
metering
mifare
minibar
minimizing
mirrored
missions
mkdtemp
mmax
mmi
mnc
moderately
moitor
mplink
mschap
msdos
msdp
mserr
msn
mtp
muhenkan
multifrequency
multimodal
multisample
multitask
mutes
narrowband
nci
ndef
neglects
negotiated
neighborhoods
netmask
nets
nextgroup
nlink
@ -338,6 +412,7 @@ nvalidates
nweb
oaep
ofb
offhook
offscreen
oncancel
onexit
@ -347,12 +422,18 @@ onmessageerror
onrepeat
oper
operated
operatorconfigs
opkey
opl
opname
osd
ott
ounted
overheated
overline
owningproperties
ows
oximeter
p2p
paramcheck
parameterf
@ -360,18 +441,28 @@ parameteri
paren
parseinfo
participating
passpoint
pastedata
patchlevel
pbo
pda
pdu
peap
persion
persistable
perso
personalisation
pertaining
photographing
pixelmap
playpause
playstate
plmn
plurals
plusminus
pmm
pnn
pobox
polylines
pooled
ppid
@ -384,13 +475,18 @@ premises
premultiplied
premultiply
prepares
presently
prevgroup
prikey
primaries
proactively
prohibits
promisify
provisioned
proxyed
psk
pss
puk
pvr
querier
queriers
@ -399,6 +495,7 @@ rasterizer
rawfile
rdb
rdev
reassociate
rebounds
recalculated
reconfiguration
@ -407,6 +504,7 @@ recovering
recursions
redirections
refill
rejects
remidner
remotedevice
removable
@ -424,15 +522,23 @@ retried
revocation
revoked
rewinding
rfcomm
rfid
rfkill
ringtone
ringtones
rle
rmdir
rotatable
rtd
rtt
ruim
rwt
s5
sac
sak
satellites
scdma
sco
screenlock
screensaver
@ -443,27 +549,40 @@ searchsetter
secinfo
seeked
semicircles
sensing
sequenceable
settingsdata
sfactor
sha1
shadertype
sharedarraybuffer
shortkey
shuts
sigalgs
silenced
slidable
sliderstyle
sm3
smil
smsc
snoozing
snorm
snr
socid
softer
sonification
sortings
spawns
spay
spdy
speakerphone
specificed
speedratings
spellcheck
spn
spp
spry
spy
ssp
stablization
statfs
@ -478,12 +597,14 @@ subpixel
subscrbers
subscribale
subscribes
subtypes
superimposed
suscribes
suspends
switchvideomode
synchronizes
synchronizing
synth
syscreen
sysevent
sysex
@ -496,12 +617,16 @@ tailoring
talkback
taskmanager
tbla
tdscdma
telecom
tethering
texel
textarget
textclock
texttimer
thirdparty
timeinterfaceimpl
tnf
totalsize
touchpad
tranlisterated
@ -514,20 +639,33 @@ trashed
traversed
truncates
tsbundle
ttls
txpower
uarfcn
ubset
ucs
udid
uint8
uitest
umalqura
unapply
unassigned
unauth
unbinding
unblocking
uncalibrated
uncatergorized
unconditional
unduck
unducked
unequal
unfocused
unhold
unicom
unicon
uniform1ui
uniforms
uninit
uninstallation
unlinked
unlocking
@ -548,28 +686,44 @@ unregisters
unremovable
unrestricted
unsecure
unsent
unspec
unsubscribes
unsuccessfully
unsupport
unsuspended
uplink
useriam
usim
ussd
utilized
uuids
uwb
v9
varyings
vibrates
vibrating
vlr
voicemail
volte
volumemanager
vorbis
vsync
wakes
waking
wallpapers
wapi
watchers
waterflow
wcdma
wcdmn
weakmap
weakset
wearables
weighing
wep
wideband
wifiext
wimax
wireframe
wordprocessor

View File

@ -18,11 +18,10 @@ const fs = require("fs");
const ts = require(path.resolve(__dirname, "../node_modules/typescript"));
const { checkAPIDecorators } = require("./check_decorator");
const { checkSpelling } = require("./check_spelling");
const { checkAPINameOfHump } = require("./check_hump");
const { checkPermission } = require("./check_permission");
const { checkSyscap } = require('./check_syscap');
const { checkDeprecated } = require('./check_deprecated');
const { hasAPINote,ApiCheckResult } = require("./utils");
const { hasAPINote, ApiCheckResult } = require("./utils");
let result = require("../check_result.json");
function checkAPICodeStyle(url) {
@ -39,8 +38,8 @@ function getMdFiles(url) {
}
function tsTransform(uFiles, callback) {
uFiles.forEach((filePath,index) => {
console.log(`scaning file in no ${++ index}!`)
uFiles.forEach((filePath, index) => {
console.log(`scaning file in no ${++index}!`)
if (/\.d\.ts/.test(filePath)) {
const content = fs.readFileSync(filePath, "utf-8");
const fileName = path.basename(filePath).replace(/.d.ts/g, ".ts");
@ -83,8 +82,6 @@ function checkAllNode(node, sourcefile, fileName) {
if (ts.isIdentifier(node)) {
// check variable spelling
checkSpelling(node, sourcefile, fileName);
// check hump naming
// checkAPINameOfHump(node, sourcefile, fileName);
}
node.getChildren().forEach((item) => checkAllNode(item, sourcefile, fileName));
}
@ -92,7 +89,7 @@ function checkAllNode(node, sourcefile, fileName) {
function scanEntry(url) {
// scan entry
checkAPICodeStyle(url);
result.scanResult.push("api_check: true");
result.scanResult.push(`api_check: ${ApiCheckResult.format_check_result}`);
return result.scanResult;
}
exports.scanEntry = scanEntry;

View File

@ -35,7 +35,7 @@ function checkDeprecated(node, sourcefile, fileName) {
} else {
errorInfo += note;
}
}
}
} else if (arr == null) {
hasDeprecatedError = true;
if (errorInfo !== "") {

View File

@ -13,11 +13,24 @@
* limitations under the License.
*/
const fs = require('fs');
const path = require('path');
const { getAPINote, ErrorType, ErrorLevel, FileType } = require('./utils');
const { addAPICheckErrorLogs } = require('./compile_info');
const permissionCheckWhitelist = new Set(['@ohos.wifi.d.ts', '@ohos.wifiManager.d.ts']);
function checkPermission(node, sourcefile, fileName) {
const permissionTags = [];
const permissionFilesPath = path.resolve(__dirname, '../../../../../',
"base/global/system_resources/systemres/main/config.json");
const content = fs.readFileSync(permissionFilesPath, 'utf-8');
const permissionFileContent = JSON.parse(content);
const permissionTagsObj = permissionFileContent.module.definePermissions;
permissionTagsObj.forEach((item) => {
permissionTags.push(item.name);
})
const permissionRuleSet = new Set(permissionTags);
const apiNote = getAPINote(node);
const apiNoteArr = apiNote.split('*');
@ -54,9 +67,12 @@ function checkPermission(node, sourcefile, fileName) {
}
});
if (hasPermissionError) {
if (hasPermissionError && !permissionCheckWhitelist.has(path.basename(fileName))) {
addAPICheckErrorLogs(node, sourcefile, fileName, ErrorType.UNKNOW_PERMISSION, errorInfo, FileType.API,
ErrorLevel.MIDDLE);
} else if (hasPermissionError && permissionCheckWhitelist.has(path.basename(fileName))) {
addAPICheckErrorLogs(node, sourcefile, fileName, ErrorType.UNKNOW_PERMISSION, errorInfo, FileType.API,
ErrorLevel.LOW);
}
}
exports.checkPermission = checkPermission;

View File

@ -13,8 +13,6 @@
* limitations under the License.
*/
const path = require('path');
const ts = require(path.resolve(__dirname, "../node_modules/typescript"));
const rules = require("../code_style_rule.json");
const { getAPINote, ErrorType, ErrorLevel, FileType } = require('./utils');
const { addAPICheckErrorLogs } = require('./compile_info');

View File

@ -13,7 +13,6 @@
* limitations under the License.
*/
const path = require("path")
const fs = require("fs")
const result = require("../check_result.json");
const { apiCheckArr, getApiInfo, ErrorLevel, ApiCheckResult } = require("../src/utils");
@ -28,13 +27,6 @@ const { apiCheckArr, getApiInfo, ErrorLevel, ApiCheckResult } = require("../src/
* @param {Enum} level enum object:ErrorLevel
*/
function addAPICheckErrorLogs(node, sourcefile, fileName, errorType, errorInfo, type, level) {
const info1 = __dirname;
const info2 = path.resolve(__dirname, "../../../../");
const info3 = path.resolve(__dirname, "../../../../../");
const info4 = fs.existsSync(path.resolve(__dirname,
"../../../../base/global/system_resources/systemres/main/config.json"));
const info5 = fs.existsSync(path.resolve(__dirname,
"../../../../../base/global/system_resources/systemres/main/config.json"));
if (level === ErrorLevel.HIGH || level === ErrorLevel.MIDDLE) {
ApiCheckResult.format_check_result = false;
}
@ -53,7 +45,7 @@ function addAPICheckErrorLogs(node, sourcefile, fileName, errorType, errorInfo,
errorType: errorType,
fileName: `${fileName}(line: ${posOfNode.line + 1}, col: ${posOfNode.character + 1})`,
type: type,
errorInfo: `${errorInfo}~~${info1}~~${info2}~~${info3}~~${info4}~~${info5}`,
errorInfo: errorInfo,
version: getApiInfo(node).version,
basename: path.basename(fileName).replace(/\.d\.ts/g, ""),
level: level